zoukankan      html  css  js  c++  java
  • 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 代码量而写的

    如果您看了本篇博客,觉得对您有所收获,请点击右下角的 [推荐]

    如果您想转载本博客,请注明出处

    如果您对本文有意见或者建议,欢迎留言

    感谢您的阅读,请关注我的后续博客

  • 相关阅读:
    输入框联想
    SyntaxError: missing ; before statement 错误的解决
    Oracle数据库DECODE函数的使用.
    MySQL ----命令总结!
    个介!
    递归函数
    闭包函数与装饰器
    函数对象
    力扣题
    函数基础
  • 原文地址:https://www.cnblogs.com/geek12/p/4215880.html
Copyright © 2011-2022 走看看