Please consider the following code, with which I try to analyze only the first comment on the phpDoc style (without using any other libraries) in the file (the contents of the file are placed in the $ data variable for testing purposes):
$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('/@([az]+)\s+(.*?)\s*(?=$|@[az]+\s)/s', $data, $matches); $info = array_combine($matches[1], $matches[2]); print_r($info)
This almost works, except for the fact that everything after @todo (including the block and comment code bar() ) is considered the value of @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... /
How does my code need to be changed so that only the first block of comments is processed (in other words: should parsing stop after the first "* /" met?
source share