php - Bibtex php preg_match_all

标签 php preg-match-all bibtex

我有一个带有 Bibtex 导出的文本文件。 该文本文件有许多遵循以下模式的条目。

@article{ls_leimeister,
  added-at = {2013-01-18T11:14:11.000+0100},
  author = {Wegener, R. and Leimeister, J. M.},
  biburl = {http://www.bibsonomy.org/bibtex/27bb26b4b4858439f81aa0ec777944ac5/ls_leimeister},
  journal = {International Journal of Technology Enhanced Learning (to appear)},
  keywords = {Challenges Communities: Factors Learning Success VirtualCommunity and itegpub pub_jml pub_rwe},
  note = {JML_390},
  title = {Virtual Learning Communities: Success Factors and Challenges},
  year = 2013
}

我想使用 php 并考虑 preg_match_all

以下内容没有让我有任何收获:

preg_match_all('/@^.*}$/', file_get_contents($file_path),$results);

我想从简单的开始,但这并没有真正起作用。 我对 php RegEx 有点陌生。

完美的最终输出是:

Array
    (
        [0] => Array
            (
                ['type'] => article
                ['unique_name'] => ls_leimeister
                ['added-at'] => 2013-01-18T11:14:11.000+0100
                ['author'] => Wegener, R. and Leimeister, J. M.
                ['biburl'] => http://www.bibsonomy.org/bibtex/27bb26b4b4858439f81aa0ec777944ac5/ls_leimeister
                ['journal'] => International Journal of Technology Enhanced Learning (to appear)
                ['keywords'] => Challenges Communities: Factors Learning Success VirtualCommunity and itegpub pub_jml pub_rwe
                ['note'] => JML_390
                ['title'] => Virtual Learning Communities: Success Factors and Challenges
                ['year'] => 2013
            )

        [1] => Array
            (
                [...] => …
            )

    )

最佳答案

试试这个:这里我只获取了typeunique_name,通过查看它,你可以获取所有其他的。

$str = '@article{ls_leimeister,
  added-at = {2013-01-18T11:14:11.000+0100},
  author = {Wegener, R. and Leimeister, J. M.},
  biburl = {http://www.bibsonomy.org/bibtex/27bb26b4b4858439f81aa0ec777944ac5/ls_leimeister},
  journal = {International Journal of Technology Enhanced Learning (to appear)},
  keywords = {Challenges Communities: Factors Learning Success VirtualCommunity and itegpub pub_jml pub_rwe},
  note = {JML_390},
  title = {Virtual Learning Communities: Success Factors and Challenges},
  year = 2013
}';

preg_match_all('/@(?P<type>\w+){(?P<unique_name>\w+),(.*)/',$str,$matches);

echo $matches['type'][0];
echo "<br>";
echo $matches['unique_name'][0];
echo "<br>";

echo "<pre>";
print_r($matches);

输出数组格式与您的格式略有不同,但您可以将此格式更改为您的格式。

关于php - Bibtex php preg_match_all,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15135083/

相关文章:

php - 我应该用什么来保存数据库中的图像

php - Javascript 或 Jquery : Getting key inputs without focus

php - 建议,php mysql transaction for insertion to multiple tables in a block

java - 德国电话号码格式的正则表达式

latex - 引用书目作为 LaTeX/BibTeX 中的部分

haskell - .bib 文件中所有 BibTex 条目的列表,以生成 Hakyll 出版物列表?

latex - 有没有办法覆盖特定条目的 bibtex 样式文件?

php - 使用 PHP 在 Linux 服务器上运行 C++ 可执行文件

涉及日语的PHP正则表达式

php数组多维索引