/** * @param $full_filename * * @return array */ public static function __readBibFile($full_filename) { self::__setCharsetToUtf8($full_filename); require_once 'Modules/Bibliographic/lib/PEAR_BibTex_1.0.0RC5/Structures/BibTex.php'; $bibtex_reader = new Structures_BibTex(); //Loading and parsing the file example.bib $bibtex_reader->loadFile($full_filename); //replace bibtex special chars with the real characters $bibtex_reader->content = self::__convertBibSpecialChars($bibtex_reader->content); $bibtex_reader->setOption('extractAuthor', false); $bibtex_reader->parse(); // Remove library-bug: if there is no cite, the library mixes up the key for the type and the first attribute. // It also shows an empty and therefore unwanted cite in the array. // // The cite is the text coming right after the type. Example: // @book {cite, // author = { "...."}, foreach ($bibtex_reader->data as $key => $entry) { if (empty($entry['cite'])) { unset($bibtex_reader->data[$key]['cite']); foreach ($entry as $attr_key => $attribute) { if (strpos($attr_key, '{') !== false) { unset($bibtex_reader->data[$key][$attr_key]); $attr_key_exploaded = explode('{', $attr_key); $bibtex_reader->data[$key]['entryType'] = trim($attr_key_exploaded[0]); $bibtex_reader->data[$key][trim($attr_key_exploaded[1])] = $attribute; } } } // formating the author to the following type of string // Smith, John / Comte, Gabriel / von Gunten Jr, Thomas foreach ($entry as $attr_key => $attribute) { if ($attr_key == 'author' && is_array($attribute)) { $attribute_string = array(); foreach ($attribute as $author_key => $author) { $lastname = array($author['von'], $author['last'], $author['jr']); $attribute_string[$author_key] = implode(' ', array_filter($lastname)); if (!empty($author['first'])) { $attribute_string[$author_key] .= ', ' . $author['first']; } } $bibtex_reader->data[$key][$attr_key] = implode(' / ', $attribute_string); } } } return $bibtex_reader->data; }
static function __readBibFile($full_filename) { require_once 'Modules/Bibliographic/lib/PEAR_BibTex_1.0.0RC5/Structures/BibTex.php'; $bibtex_reader = new Structures_BibTex(); //Loading and parsing the file example.bib $ret = $bibtex_reader->loadFile($full_filename); $bibtex_reader->setOption("extractAuthors", false); $bibtex_reader->parse(); // Remove library-bug: if there is no cite, the library mixes up the key for the type and the first attribute. // It also shows an empty and therefore unwanted cite in the array. // // The cite is the text coming right after the type. Example: // @book {cite, // author = { "...."}, foreach ($bibtex_reader->data as $key => $entry) { if (empty($entry['cite'])) { unset($bibtex_reader->data[$key]['cite']); foreach ($entry as $attr_key => $attribute) { if (strpos($attr_key, '{') !== false) { unset($bibtex_reader->data[$key][$attr_key]); $attr_key_exploaded = explode('{', $attr_key); $bibtex_reader->data[$key]['entryType'] = trim($attr_key_exploaded[0]); $bibtex_reader->data[$key][trim($attr_key_exploaded[1])] = $attribute; } } } } return $bibtex_reader->data; }
<?php require_once 'BibTex.php'; $bibtex = new Structures_BibTex(); $bibtex->setOption('extractAuthors', false); $ret = $bibtex->loadFile('publis/Gramfort.bib'); if (PEAR::isError($ret)) { die($ret->getMessage()); } $bibtex->parse(); function clean_bibtex_string($str) { $bad_chars = array('{', '}'); return str_replace($bad_chars, "", $str); } function br2nl($str) { return preg_replace('/<br(\\s*)>/i', '\\n', $str); } function short_name($name) { $l = explode(',', $name); if (count($l) > 1) { $first = trim($l[1]); $last = $l[0]; } else { $l = explode(' ', $name); $first = $l[0]; $last = $l[1]; } $sname = $first[0] . '. ' . $last;