찾다
php教程PHP源码统计代码行数和过滤注释

#!/usr/local/bin/php -f
<?php

/// 获取命令行参数
$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 );
        }
    }
}

?>

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

SublimeText3 Linux 새 버전

SublimeText3 Linux 새 버전

SublimeText3 Linux 최신 버전

에디트플러스 중국어 크랙 버전

에디트플러스 중국어 크랙 버전

작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

Dreamweaver Mac版

Dreamweaver Mac版

시각적 웹 개발 도구