<?php
//计算某目录下指定类型文件总行数
function get_all_files( $path ){
$list = array();
foreach( glob( $path . ‘/*’) as $item ){
if( is_dir( $item ) ){
$list = array_merge( $list , get_all_files( $item ) );
}
else{
$list[] = $item;
}
}
return $list;
}
function fileext($filename) {
return trim(substr(strrchr($filename, ‘.’), 1, 10));
}
$filepath = dirname(__FILE__);
$files = get_all_files($filepath);
$countLine = $thisLine =0;
//逻辑处理开始
foreach($files as $file){
if(fileext($file) != ‘php’){
//echo ‘<br>file–‘.$file.’不是有效php文件,跳过’;
} else {
$thisLine = count(file($file));
//echo ‘<br>file–‘.$file.’:’.$thisLine;
$countLine+=$thisLine;
}
}
echo $filepath . “<br>———总行数count:”.$countLine;
?>
比格高
逼格更高