扣丁书屋

根据文件后缀判断是否为代码文件

2年以前  |  阅读数:181 次  |    

    function is_code_file($path)
    {
        if($path == null){
            return false;
        }

        $ext = pathinfo($path,PATHINFO_EXTENSION);
        $basename = pathinfo($path,PATHINFO_BASENAME);

        $codeFileExt = array( ".m",".pch",".strings",".plist",".xcworkspacedata",".java",".c",".cpp",".sh", ".py",".h",".cc",".mk",".xml",".rc",".txt",".conf",".js",".html",".shtml",".aidl",".css",".php",".gradle",".properties" );
        $codeFileName = array( "Makefile");

        if(in_array('.' . $ext,$codeFileExt)){
            return true;
        }

        if(in_array($basename, $codeFileName)){
            return true;
        }

        return false;
    }

相关文章: