PHP采集屏蔽统计代码,统计代码行数与过滤注释的php代码

/// 获取命令行参数

/// by http://www.jquerycn.cn

$fileName = $argv[1];

if ( ! is_dir( $fileName ) && ! file_exists( $fileName ) ) {

echo "Usage: ".$argv[0]." [path|file]\n";

exit;

}

$disableFile = "DMO|test_|FileZip|jpgraph|smarty|tourdata|demo_|Frame|socket.php|IDNA2.php|timezone.php|config.db.php|config.php";

$disableFile .= "|main1.php|obj.php|interface.php|hmac.php|php-excel.class.php|cfg.class.php|global.php|gconfig.php|main2.php|sinfo.php";

$disableFile .= "|main.php|index.php|mod_tpl.php|redis.lua|^_";

$disableDir = "cache$|templates$|templates_c$|adodb$|smarty$|mailer$|biz$|test$";

$ext = "\.php$|\.c$|\.h$|\.go$|\.lua$";

if ( is_dir( $fileName ) ) {

getDir( $fileName );

} else {

echoCode( $fileName );

}

function echoCode( $fileName ) {

$fileLines = file( $fileName );

$lineCount = 0;

foreach( $fileLines AS $line ) {

$line = str_replace( "\t", "    ", $line );

$tr = trim( $line );

if ( preg_match( "/\\*|^\*|^ {1,}\*|\/\*|\*\/|^ {1,}\/\/|^\/\//", $line ) || $tr === "" ) {

continue;

}

$lineCount++;

$line = str_replace( "\r", "", $line );

$line = str_replace( "\n", "", $line );

echo "".$line."\n";

}

echo "\n";

}

function getDir( $path ) {

global $disableFile, $disableDir, $ext;

$dDirs = dir( $path );

while ( false !== ( $fileDirs = $dDirs->read() ) ) {

$sCodeFile = $path . "/".$fileDirs;

if ( $fileDirs == "." || $fileDirs == ".."  || preg_match("/".$disableDir."/", $fileDirs ) ) {

continue;

}

if ( ! is_dir( $sCodeFile ) && ! file_exists( $sCodeFile ) ) {

continue;

}

if ( preg_match( "/".$disableFile."/", $fileDirs ) ||

( ! is_dir( $sCodeFile ) && ! preg_match( "/".$ext."/", $fileDirs ) ) ) {

continue;

}

if ( is_dir( $sCodeFile ) ) {

getDir( $sCodeFile );

continue;

} else {

//echo $sCodeFile."\n";

echo iconv( "UTF-8", "GBK", "文件名: ").$fileDirs."\n";

//echo "文件名: ".$fileDirs."\n";

echoCode( $sCodeFile );

}

}

}

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值