Introduction – Introduction to Structures_BibTex


This package provides methods to access information stored in a BibTex file. During parsing it is possible to let the data be validated. In addition. the creation of BibTex Strings as well as RTF Strings is also supported.

A few examples

Loading a BibTex File and printing the parsed array

require_once 'Structures/BibTex.php';
$bibtex = new Structures_BibTex();
$ret    $bibtex->loadFile('foo.bib');
if (
PEAR::isError($ret)) {


Options can be set either in the constructor or with the method setOption(). When setting in the constructor the options are given in an associative array. The options are:

  • stripDelimiter (default: true) Stripping the delimiter surrounding the entries.

  • validate (default: true) Validation while parsing.

  • unwrap (default: false) Unwrapping entries while parsing.

  • wordWrapWidth (default: false) If set to a number higher one that the entries are wrapped after that amount of characters.

  • wordWrapBreak (default: \n) String used to break the line (attached to the line).

  • wordWrapCut (default: 0) If set to zero the line will we wrapped at the next possible space, if set to one the line will be wrapped exactly after the given amount of characters.

  • removeCurlyBraces (default: false) If set to true Curly Braces will be removed.

Example of setting options in the constructor:

Setting options in the constructor

= new Structures_BibTex(array('validate'=>false'unwrap'=>true));

Example of setting options using the method setOption():

Setting options using setOption

= new Structures_BibTex();

Stored Data

The data is stored in the class variable data. This is a a list where each entry is a hash table representing one bibtex-entry. The keys of the hash table correspond to the keys used in bibtex and the values are the corresponding values. Some of these keys are:

  • cite - The key used in a LaTeX source to do the citing.

  • entryType - The type of the entry, like techreport, book and so on.

  • author - One or more authors of the entry. This entry is also a list with hash tables representing the authors as entries. The author has table is explained later.

  • title - Title of the entry.


As described before the authors are stored in a list. Every entry representing one author as a has table. The hash table consits of four keys: first, von, last and jr. The keys are explained in the following list:

  • first - The first name of the author.

  • von - Some names have a 'von' part in their name. This is usually a sign of nobleness.

  • last - The last name of the author.

  • jr - Sometimes a author is the son of his father and has the same name, then the value would be jr. The same is true for the value sen but vice versa.

Adding an entry

To add an entry simply create a hash table with the needed keys and values and call the method addEntry().

Adding an entry

= new Structures_BibTex();
$addarray                       = array();
$addarray['entryType']          = 'Article';
$addarray['cite']               = 'art2';
$addarray['title']              = 'Titel of the Article';
$addarray['author'][0]['first'] = 'John';
$addarray['author'][0]['last']  = 'Doe';
$addarray['author'][1]['first'] = 'Jane';
$addarray['author'][1]['last']  = 'Doe';
Structures_BibTex (Previous) Usage of warnings when using Structures_BibTex (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.