php 计算代码行数

<?php 
header("Content-type:text/html;charset=utf-8");

// php 递归计算文件夹代码行数
function codeLine($file){
	return count(file($file));
}
error_reporting(0); // 屏蔽notice 错误
$lines = 0;

function forDir($path){
	
	if(!is_dir($path)){
		return null;
	}
	// $arr 数组里面放你要计算文件的后缀
	$arr = array("php");
	$dh = opendir($path);
	while(($dir = readdir($dh)) !== false){
		if($dir != "." && $dir != ".."){
			if(is_dir($path . "/" . $dir)){
				$lines += forDir($path . "/" . $dir);
			}else{
				foreach($arr as $v){
					if(str_replace(".","",strrchr($dir,".")) == $v){
						$lines += codeLine($path . "/" . $dir);
					}
				}
			}
		}
	}
	closedir($dh);
	return $lines;
}

 为了计算 Thinkphp 代码量而写的

posted @ 2015-01-10 23:03  诚人小李  阅读(640)  评论(0编辑  收藏  举报