Created
February 3, 2012 05:33
-
-
Save tacke758/1728343 to your computer and use it in GitHub Desktop.
Generate thesis reference bibitem line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$line = 'design Design of Evolvable Computer Languages 2002 IEEE TRANSACTIONS ON EVOLUTIONARY COMPUTATION 6 4 420-424 Charles Ofria Christoph Adami Travis C. Collier'; // delimiter is tabstop | |
print thesis_reference_line($line); | |
// for each line of file | |
function thesis_reference_line($line) | |
{ | |
// split with tab | |
$datas = explode("\t", $line); | |
// init variables (or this function'f feature) | |
$item = $datas[0]; | |
$thesis = $datas[1]; | |
$year = $datas[2]; | |
$magazine = $datas[3]; | |
$vol = $datas[4]; | |
$num = $datas[5]; | |
$page = $datas[6]; | |
$authors = array_slice($datas, 7); | |
$ref = ""; | |
// add bibitem control | |
$ref .= '\\bibitem{' . $item . '} '; | |
// add authors | |
$authors_except_last = array_slice($authors, 0, count($authors) - 1); | |
$author_last = $authors[count($authors) - 1]; | |
$ref .= implode(', ', $authors_except_last) . ' and ' . $author_last; | |
$ref .= ', '; | |
// add thesis title | |
$ref .= '``' . $thesis . ',"'; // use tex quote syntax | |
$ref .= ', '; | |
// add magazine | |
$ref .= '\emph{' . $magazine . '}'; // tex italic | |
// add volume | |
if ($vol !== "") | |
{ | |
$ref .= 'Vol. ' . $vol; | |
$ref .= ', '; | |
} | |
// add number | |
if ($num !== "") | |
{ | |
$ref .= 'No. ' . $num; | |
$ref .= ', '; | |
} | |
// add page number | |
if ($page !== "") | |
{ | |
$ref .= 'pp. ' . $page; | |
$ref .= ', '; | |
} | |
if ($year !== "") | |
{ | |
$ref .= '(' . $year . ')'; | |
} | |
$ref .= '.'; | |
$ref .= "\n"; | |
return $ref; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment