ファイル内の最初の phpDoc スタイルのコメント (他のライブラリは使用しない) のみを解析しようとしている次のコードを検討してください (ファイルの内容は、テスト目的で $data 変数に入れられます)。
$data = "
/**
* @file A lot of info about this file
* Could even continue on the next line
* @author me@example.com
* @version 2010-05-01
* @todo do stuff...
*/
/**
* Comment bij functie bar()
* @param Array met dingen
*/
function bar($baz) {
echo $baz;
}
";
$data = trim(preg_replace('/\r?\n *\* */', ' ', $data));
preg_match_all('/@([a-z]+)\s+(.*?)\s*(?=$|@[a-z]+\s)/s', $data, $matches);
$info = array_combine($matches[1], $matches[2]);
print_r($info)
@todo の後のすべて (コメント ブロックとコードを含む)bar()
が の値と見なされるという事実を除いて、これはほとんど機能し@todo
ます。
Array (
[file] => A lot of info about this file Could even continue on the next line
[author] => me@example.com
[version] => 2010-05-01
[todo] => do stuff... /
/** Comment bij functie bar()
[param] => Array met dingen /
function bar() {
echo ;
}
)
最初のコメント ブロックのみが解析されるようにコードをどのように変更する必要がありますか (つまり、最初の "*/" が検出された後に解析を停止する必要があります)