zoukankan      html  css  js  c++  java
  • php获取代码总行数

    <?php
    ini_set('max_execution_time', '0');
    function code_linenum($path, $i) {
        if (!is_dir($path)) {
            return false;
        }
        $files = glob($path . '/*');
        if ($files) {
            foreach ($files as $file) {
                if (is_dir($file)) {
                    code_linenum($file, $i);
                }
                $buffer = '';
                $handle = @fopen($file, 'r');
                if ($handle) {
                    while(!feof($handle)) {
                        $buffer = fgets($handle,4096);
                        $buffer = trim($buffer);    //同等于==$buffer = str_replace("
    ", '', $buffer);
                        if (!empty($buffer)) {
                            $comments = array();
                            $comments[0]  = '';
                            $comments[0] .= preg_match('////i', $buffer) ? '####' : '';
                            $comments[0] .= preg_match('//**/i', $buffer) ? '####' : '';
                            $comments[0] .= preg_match('/*s/i', $buffer) ? '####' : '';
                            $comments[0] .= preg_match('/*//i', $buffer) ? '####' : '';
                            if (empty($comments[0])) {
                                global $i;
                                $i++;
                            }
                        }
                    }
                    fclose($handle);
                }
            }
        }
        return $i;
    }
    //调用函数
    global $i;
    $linenums =  code_linenum('D:/guozi/V3.0' ,$i);
    echo '代码总行数为:' . $linenums;
  • 相关阅读:
    高一下期末考试划水记
    BZOJ 1053
    积性函数与狄利克雷卷积(未完待更)
    Contest Hunter 3101
    POJ2689
    3.17爆零赛
    全概率公式
    矩阵快速幂
    模板练习
    _rqy's Code Style for OI
  • 原文地址:https://www.cnblogs.com/aifengguo/p/8861990.html
Copyright © 2011-2022 走看看