\BIBTEXPARSE

BibTeX PARSE

Summary

Methods
Properties
Constants
__construct()
openBib()
loadBibtexString()
loadStringMacro()
closeBib()
getLine()
extractStringValue()
fieldSplit()
reduceFields()
fullSplit()
parseEntry()
removeDelimiters()
explodeString()
closingDelimiter()
removeDelimitersAndExpand()
extractEntries()
returnArrays()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

__construct()

__construct() : 

BIBTEXPARSE

For a quick command-line test (php -f PARSEENTRIES.php) after installation, uncomment these lines:

Parse a file $parse = NEW PARSEENTRIES(); $parse->expandMacro = TRUE; // $array = array("RMP" =>"Rev., Mod. Phys."); // $parse->loadStringMacro($array); // $parse->removeDelimit = FALSE; // $parse->fieldExtract = FALSE; $parse->openBib("bib.bib"); $parse->extractEntries(); $parse->closeBib(); list($preamble, $strings, $entries, $undefinedStrings) = $parse->returnArrays(); print_r($preamble); print "\n"; print_r($strings); print "\n"; print_r($entries); print "\n\n";

// Parse a bibtex PHP string $bibtex_data = <<< END

\@STRING{three = "THREE"} \@STRING{two = "TWO"} \@string{JRNL23 = {NatLA 23 } # " " # two # " " # three}

\@article{klitzing.1, author = "v. Klitzing and Dorda and Pepper", title = "New method for high mark@sirfragalot.com accuracy determination of fine structure constant based on quantized hall resistance", volume = "45", journal = {Journal of } # JRNL23, pages = "494", citeulike-article-id = {12222 } , ignoreMe = {blah}, }

\@article { klitzing.2, author = "Klaus von Klitzing", title = "The Quantized Hall Effect", volume = "58", journal = two, pages = "519", }

END;

$parse = NEW PARSEENTRIES(); $parse->expandMacro = TRUE; // $parse->removeDelimit = FALSE; // $parse->fieldExtract = FALSE; $array = array("RMP" =>"Rev., Mod. Phys."); $parse->loadStringMacro($array); $parse->loadBibtexString($bibtex_data); $parse->extractEntries(); list($preamble, $strings, $entries, $undefinedStrings) = $parse->returnArrays(); print_r($preamble); print "\n"; print_r($strings); print "\n"; print_r($entries); print "\n\n";

Returns

openBib()

openBib(  file) : 

Open bib file

Parameters

file

Returns

loadBibtexString()

loadBibtexString(  bibtex_string) : 

Load a bibtex string to parse it

Parameters

bibtex_string

Returns

loadStringMacro()

loadStringMacro(mixed||string|int  macro_array) : 

Set strings macro

Parameters

mixed||string|int macro_array

Returns

closeBib()

closeBib() : 

Close bib file

Returns

getLine()

getLine() : 

Get a non-empty line from the bib file or from the bibtexString

Returns

extractStringValue()

extractStringValue(  string) : 

Extract value part of @string field enclosed by double-quotes or braces.

The string may be expanded with previously-defined strings

Parameters

string

Returns

fieldSplit()

fieldSplit(  seg) : mixed||string|int

Extract a field

Parameters

seg

Returns

mixed||string|int —

reduceFields()

reduceFields(  oldString) : 

Extract and format fields

Parameters

oldString

Returns

fullSplit()

fullSplit(  entry) : 

Start splitting a bibtex entry into component fields.

Store the entry type and citation.

Parameters

entry

Returns

parseEntry()

parseEntry(  entry) : 

Grab a complete bibtex entry

Parameters

entry

Returns

removeDelimiters()

removeDelimiters(  string) : 

Remove delimiters from a string

Parameters

string

Returns

explodeString()

explodeString(  val) : mixed||string|int

This function works like UTF8::mb_explode('#',$val) but has to take into account whether

the character # is part of a string (i.e., is enclosed into "..." or {...} ) or defines a string concatenation as in @string{ "x # x" # ss # {xx{x}x} }

Parameters

val

Returns

mixed||string|int —

closingDelimiter()

closingDelimiter(  val,   delimitBegin,   delimitEnd) : 

This function receives a string and a closing delimiter '}' or ')'

and looks for the position of the closing delimiter taking into account the following Bibtex rules: Inside the braces, there can arbitrarily nested pairs of braces, but braces must also be balanced inside quotes! Inside quotes, to place the " character it is not sufficient to simply escape with \": Quotes must be placed inside braces.

Parameters

val
delimitBegin
delimitEnd

Returns

(0)

removeDelimitersAndExpand()

removeDelimitersAndExpand(  string,   inpreamble = FALSE) : 

Remove enclosures around entry field values. Additionally, expand macros if flag set.

Parameters

string
inpreamble

Default is FALSE

Returns

extractEntries()

extractEntries() : 

This function extract entries taking into account how comments are defined in BibTeX.

BibTeX splits the file in two areas: inside an entry and outside an entry, the delimitation being indicated by the presence of a @ sign. When this character is met, BibTex expects to find an entry. Before that sign, and after an entry, everything is considered a comment!

Returns

returnArrays()

returnArrays() : mixed||string|int

Return arrays of entries etc. to the calling process.

Returns

mixed||string|int —

(preamble, strings, entry, undefinedStrings)