Example #1
0
 /**
  * Extract the BibTeX data.
  *
  * @param string $data
  * @return array
  */
 private function extract($data)
 {
     $data = trim($data) . "\n";
     $parser = new \PARSEENTRIES();
     $parser->expandMacro = true;
     $parser->removeDelimit = true;
     $parser->loadBibtexString($data);
     $parser->extractEntries();
     $bibTeX = $parser->returnArrays();
     $bibTeX = $bibTeX[2];
     $length = count($bibTeX);
     $author = new \PARSECREATORS();
     $date = new \PARSEMONTH();
     $page = new \PARSEPAGE();
     for ($i = 0; $i < $length; $i++) {
         if (isset($bibTeX[$i]['author']) == true) {
             $bibTeX[$i]['author'] = $author->parse($bibTeX[$i]['author']);
         }
         if (isset($bibTeX[$i]['editor']) == true) {
             $bibTeX[$i]['editor'] = $author->parse($bibTeX[$i]['editor']);
         }
         if (isset($bibTeX[$i]['month']) == true) {
             $bibTeX[$i]['month'] = $date->init($bibTeX[$i]['month']);
         }
         if (isset($bibTeX[$i]['pages']) == true && $bibTeX[$i]['pages'] != '' && preg_match('/^[0-9]+$/', $bibTeX[$i]['pages']) == 0) {
             $bibTeX[$i]['pages'] = $page->init($bibTeX[$i]['pages']);
         }
     }
     return $bibTeX;
 }
Example #2
0
    /**
     * Extracting the authors
     *
     * @access private
     * @param string $entry The entry with the authors
     * @return array the extracted authors
     */
    function _extractAuthors($authors) {
      // Use OSBib way of parsing authors
      require_once("PARSECREATORS.php");
      $parseCreators = new PARSECREATORS();
      $creators = $parseCreators->parse($authors);
      foreach($creators as &$cArray) {
	$cArray = array(
			"surname" => trim($cArray[2]),
			"firstname" => trim($cArray[0]),
			"initials" => trim($Array[1]),
			"prefix" => trim($cArray[3])
			);
	unset($cArray);
      }
      return new BibtexCreators($creators);
    }
Example #3
0
<?php

namespace Hasantayyar\Osbib\Format\BibtextParse;

//include("PARSECREATORS.php");
//include("PARSEENTRIES.php");
//include("PARSEMONTH.php");
//include("PARSEPAGE.php");
// some samle usage
$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) = $parse->returnArrays();
print_r($preamble);
print "\n";
print_r($strings);
print "\n";
print_r($entries);
print "\n\n";
$authors = "Mark N. Grimshaw and Bush III, G.W. & M. C. Hammer Jr. and von Frankenstein, Ferdinand Cecil, P.H. & Charles Louis Xavier Joseph de la Vallee Poussin";
$creator = new PARSECREATORS();
$creatorArray = $creator->parse($authors);
print_r($creatorArray);