nic*_*ckf 9 php reflection comments
我正在做一些自制的自动化文档,因为我的代码库布局不是很标准,我想知道读取PHP文件和获取注释块内容的最佳方法是什么.我能想到的唯一方法是打开文件并逐行阅读,但是想到可能有一些内置的魔法会为我解析文档,类似于Reflection函数.
每个文件的基本布局如下:
<?php // $Id$
/**
* Here is this script's documentation, with information in pseudo-javadoc
* type tags and whatnot.
*
* @attr something some information about something
* @attr etc etc etc
*/
// rest of the code goes here.
Run Code Online (Sandbox Code Playgroud)
请务必注意,这些文件中没有定义任何函数或类.这些评论与整个剧本有关.
Pao*_*ino 16
查看Tokenizer.
要获取名为test.php您的文件中的所有注释,请执行以下操作:
$tokens = token_get_all(file_get_contents("test.php"));
$comments = array();
foreach($tokens as $token) {
if($token[0] == T_COMMENT || $token[0] == T_DOC_COMMENT) {
$comments[] = $token[1];
}
}
print_r($comments);
Run Code Online (Sandbox Code Playgroud)