For currently supported version of MARCspec - A common MARC record path language see http://marcspec.github.io/ .
Installation
Installation can be done by using composer. Just run
composer require ck/php-marcspec
PHP-MARCspec requires PHP 5.4 or later.
Usage
<?phprequire("vendor/autoload.php");
useCK\MARCspec\MARCspec;
useCK\MARCspec\Field;
useCK\MARCspec\Subfield;
useCK\MARCspec\ComparisonString;
useCK\MARCspec\SubSpec;
// parse and access MARCspec like an array$fixed = newMARCspec('007[0]/1-8{/0=\a}');
$fixed['field']; // CK\MARCspec\FieldInterfaceecho$fixed['field']['tag']; // '007'echo$fixed['field']['charStart']; // 1echo$fixed['field']['charEnd']; // 8echo$fixed['field']['charLength']; // 8$fixed['field']['subSpecs'][0]['leftSubTerm']; // CK\MARCspec\MARCspecInterfaceecho$fixed['field']['subSpecs'][0]['leftSubTerm']; // '007[0]/0'echo$fixed['field']['subSpecs'][0]['operator']; // '='$fixed['field']['subSpecs'][0]['rightSubTerm']; // CK\MARCspec\ComparisonStringInterfaceecho$fixed['field']['subSpecs'][0]['rightSubTerm']; // '\a'echo$fixed['field']['subSpecs'][0]['rightSubTerm']['comparable']; // 'a'$fixed; // CK\MARCspec\MARCspecInterfaceecho$fixed; // '007[0]/1-8{007[0]/0=\a}'$variable = newMARCspec('245^1');
echo$variable['field']['tag']; // '245'echo$variable['indicator']; // CK\MARCspec\IndicatorInterfaceecho$variable['indicator']['position']; // '1'$variable; // CK\MARCspec\MARCspecInterfaceecho$variable; // '245^1'$complex = newMARCspec('020$a{$q[0]~\pbk}{$c/0=\€|$c/0=\$}');
echo$complex['field']['tag']; // '020'$complex['subfields']; // Array$complex['subfields'][0]['tag']; // CK\MARCspec\SubfieldInterfaceecho$complex['subfields'][0]['tag']; // 'a'$complex['a'][0]['subSpecs'][0]['leftSubTerm']; // CK\MARCspec\MARCspecInterfaceecho$complex['a'][0]['subSpecs'][0]['leftSubTerm']; // '020$q[0]'echo$complex['a'][0]['subSpecs'][0]['operator']; // '~'$complex['a'][0]['subSpecs'][0]['rightSubTerm']; // CK\MARCspec\ComparisonStringInterfaceecho$complex['a'][0]['subSpecs'][0]['rightSubTerm']['comparable']; // 'pbk'echo$complex['a'][0]['subSpecs'][1][0]['leftSubTerm']; // '020$c/0'echo$complex['a'][0]['subSpecs'][1][0]['leftSubTerm']['c'][0]['charStart']; // 0echo$complex['a'][0]['subSpecs'][1][0]['leftSubTerm']['c'][0]['charEnd']; // 0echo$complex['a'][0]['subSpecs'][1][0]['leftSubTerm']['c'][0]['charLength']; // 1echo$complex['a'][0]['subSpecs'][1][0]['operator']; // '='echo$complex['a'][0]['subSpecs'][1][0]['rightSubTerm']['comparable']; // '€'echo$complex['a'][0]['subSpecs'][1][1]['leftSubTerm']; // '020$c/0'echo$complex['a'][0]['subSpecs'][1][1]['leftSubTerm']['c'][0]['charStart']; // 0echo$complex['a'][0]['subSpecs'][1][1]['leftSubTerm']['c'][0]['charEnd']; // 0echo$complex['a'][0]['subSpecs'][1][1]['leftSubTerm']['c'][0]['charLength']; // 1echo$complex['a'][0]['subSpecs'][1][1]['operator']; // '='echo$complex['a'][0]['subSpecs'][1][1]['rightSubTerm']['comparable']; // '$'// creating MARCspec// creating a new Field$Field = newField('...');
// creating a new MARCspec by setting the Field$MARCspec = MARCspec::setField($Field);
// creating a new Subfield$Subfield = newSubfield('a');
// adding the Subfield to the MARCspec$MARCspec->addSubfields($Subfield);
// creating instances of MARCspec and ComparisonString$LeftSubTerm = newMARCspec('...$a/#');
$RightSubTerm = newComparisonString(',');
// creating a new SubSpec with instances above and an operator '='$SubSpec = newSubSpec($LeftSubTerm,'=',$RightSubTerm);
// adding the SubSpec to the Subfield$Subfield['subSpecs'] = $SubSpec;
// whole MARCspececho$MARCspec; // '...[0]$a{...$a/#-#=\,}'
ArrayAccess vs. Methods
MARCspec can be accessed like an immutable array with the following offsets or with its correponding methods (see source code for documentation of all methods).