Есть комментарий к функции: Код (Text): /** * This is simple function * * This is big description * of current function * * @category CategoryName * @author Original Author <author@example.com> * @author Another Author <another@example.com> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_01.txt PHP License 3.01 * @link http://pear.php.net/package/PackageName * @see NetOther, Net_Sample::Net_Sample() * @since File available since Release 1.2.0 * @deprecated File deprecated in Release 2.0.0 */ Необходимо разобрать на массив весь комментарий, где параметры начинающиеся с @ - должны выглядеть так: Код (Text): array( 'category' => 'CategoryName', 'author' => array( 'Another Author <another@example.com>', 'Original Author <author@example.com>' ), ); Думаю о регулярках. Может кто-то видел готовые парсеры?
Можно и так, а можно вообще без единого регулярного выражения. Вы бы показали то, что уже пытались сделать сами.
Использую такую регулярку: preg_match( "(?<=[\s])[$@\w\s]*(?=[\s"])", $el, $m ) Но пока не сдвинулось с точки
Получилось как-то так: Код (Text): $results = array(); $segments = explode( '*', $fn_data['comment'] ); foreach($segments as $segment) { // Strip trailing/leading whitespace and line breaks $segment = trim( $segment, '/' ); $segment = trim( $segment ); if ( $segment[0] !== "@" && $segment[0] !== "" ) { // Description of function $results['desc'] .= $segment . ' '; } elseif ( $segment[0] === "@" ) { $el = explode( ' ', $segment ); // Find the first space, usually after @xxxx text $pos = strpos( ' ', $segment ); // rest of the string $value = substr( $segment, $pos+1 ); $name = str_replace( '@', '', $el[0] ); $results[$name] = trim( str_replace( $name, '', $value ) ); } } Из этого: Код (Text): /** * This is simple function. * * This is big description * of current function. * * @category CategoryName * @package PackageName * @author Original Author <author@example.com> * @author Another Author <another@example.com> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_01.txt PHP License 3.01 * @version SVN: $Id$ * @param String|Int параметр1 * @param Array параметр2 * @link http://pear.php.net/package/PackageName * @see NetOther, Net_Sample::Net_Sample() * @since File available since Release 1.2.0 * @deprecated File deprecated in Release 2.0.0 */ Получается это: Код (Text): Array ( [desc] => This is simple function. This is big description of current function. [category] => CategoryName [package] => PackageName [author] => Another Author [copyright] => 1997-2005 The PHP Group [license] => http://www.php.net//3_01.txt PHP License 3.01 [version] => SVN: $Id$ [param] => Array параметр2 [link] => http://pear.php.net/package/PackageName [see] => NetOther, Net_Sample::Net_Sample() [since] => File available Release 1.2.0 [deprecated] => File in Release 2.0.0 )
Близко. Если идти по вашему пути, то код можно доработать таким образом (результат в песочнице): PHP: <?php $results = [ 'descr' => [] ]; $segments = explode('*', $str); foreach($segments as $segment) { if(($segment = trim($segment, '/ '.PHP_EOL)) != '') { if(strpos($segment, '@') === 0) { $p = strpos($segment, ' '); $results[trim(substr($segment, 0, $p), '@')][] = trim(substr($segment, $p)); } else { $results['descr'][] = $segment; } } } $results['descr'] = implode(' ', $results['descr']); print_r($results); --- Добавлено --- P.S. Т.к. могут быть дескрипторы без значений, 10-ую строку можно изменить: PHP: // Вместо $p = strpos($segment, ' '); // Пишем $p = ($p = strpos($segment, ' ')) ? $p : strlen($segment);