2

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
            (
                [...] => …
            )

    )
4

2 に答える 2

2

これを試してみてください: ここでは だけを取得しました。これを見ると、他のすべてを取得できます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);

出力配列フォーマットはあなたのものとは少し異なりますが、このフォーマットをあなたのものに変更することができます。

于 2013-02-28T12:13:14.747 に答える