我是靠谱客的博主 要减肥石头,这篇文章主要介绍php代码注释统计工具,php代码统计工具,现在分享给大家,希望可以做个参考。

工具使用php编写,要求文件下下的文件为php文件(也就是以.php结尾的文件),可以统计一个文件夹下的php代码量,代码如下:

$filename = "D:/code/";//php代码所在目录

$counts = 0;

function codeCount($filename)

{

global $counts;

$total = 0; // 总行数

$space = 0; // 空行数

$notes = 0; // 注释

$handle = fopen($filename, "r");

$isNotes = false;

while (! feof($handle)) {

$line = fgets($handle);

$total ++;

if ($isNotes) {

$notes ++;

if (preg_match("/.*(*/)/", $line)) { // 多行*/注释结束

$isNotes = false;

}

continue;

}

if (preg_match("/^[s]*$/", $line)) { // 空行

$space ++;

} elseif (preg_match("/^[s]*///", $line)) { // 两杠注释

$notes ++;

} elseif (preg_match("/^[s]*(/*).*(*/)[s]*$/", $line)) { // 单行注释

$notes ++;

} elseif (preg_match("/^[s]*(/*).*/", $line)) { // 多行/*注释开始

$notes ++;

$isNotes = true;

}

}

echo "total:" . $total . "rn";

echo "space:" . $space . "rn";

echo "notes:" . $notes . "rn";

echo "
";

$counts += ($total - $space - $notes);

}

if (is_file($filename)) {

codeCount($filename);

} else

if (is_dir($filename)) {

if ($dh = opendir($filename)) {

while (($file = readdir($dh)) != false) {

// 文件名的全路径 包含文件名

$filePath = $filename . $file;

// 获取文件修改时间

if (is_file($filePath)) {

codeCount($filePath);

}

}

closedir($dh);

}

}

echo "
" . $counts;//输出总的代码量

?>



原文:http://blog.csdn.net/kakarot5/article/details/44750399

最后

以上就是要减肥石头最近收集整理的关于php代码注释统计工具,php代码统计工具的全部内容,更多相关php代码注释统计工具内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(110)

评论列表共有 0 条评论

立即
投稿
返回
顶部