我是靠谱客的博主 粗暴黑裤,这篇文章主要介绍首页> 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 "<br>";
    $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 "<br>" . $counts;//输出总的代码量
?>

最后

以上就是粗暴黑裤最近收集整理的关于首页> php教程> 正文 php代码统计工具的全部内容,更多相关首页>内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部