Created
January 20, 2015 15:06
-
-
Save Bloodb0ne/69e840c61d011b232246 to your computer and use it in GitHub Desktop.
This file contains 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 | |
//Helpers | |
function s($text){ | |
return "\"".trim($text," }{")."\""; | |
} | |
function m1($m){ | |
return s($m[1]) . ":" . s($m[2]); | |
} | |
function m2($m){ | |
return s($m[1]) . ":" . s($m[2]).","; | |
} | |
//Parse function | |
function bibtexToJson($filename){ | |
$content = file_get_contents($filename); | |
$content = preg_replace("/\@(\w)*\{(.*),/","",$content); | |
$content = mb_substr($content,0,strrpos($content,"}")); | |
$content = preg_replace_callback("/(\\w+)\\s*=\\s*\\{([\\/\sa-zA-Z0-9.:,\}\{\-#]*)\\}/","m1", $content); | |
$content = preg_replace_callback("/(\w+)\s*=\s*([?!\}\/\\\sa-zA-Z0-9.:,\#]*),/","m2",$content); | |
return json_decode("{".$content."}",true); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment