Home  >  Article  >  Backend Development  >  A tool that can find all Chinese characters in the source code_PHP tutorial

A tool that can find all Chinese characters in the source code_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:01:05908browse

A tool that can find all Chinese characters in the source code

Just fill in the path you want to find $sf.

Function
1 Find all Chinese characters
2 Ignore Chinese characters in comment sentences
3 Add files and folders that need to be ignored
4 Generate log files

If you are worried about updating the language pack for your software
Please use this tool.

My example:
http://127.0.0.1/tools/searchcn.php
http://127.0.0.1/tools/cnlog.txt

Copy code The code is as follows:

set_time_limit(0);
ob_implicit_flush();

//Comment format
$remark = array(
array('/ /debug', "rn")
, array('/**', '*/')
, array('/*debug<🎝>*/')
, array('/ *note<🎝>*/')
, array('//note', "rn")
);

//The following directories and files are not queried
$filter = 'forumdata|config.inc.php|debug|test|readme|utilities|upgrade|.tpl.php|index.htm|.lang.php';

//Project Directory
$sf = 'd:\data\labs\develop\dzhead\';

//Log directory
$logname = 'cnlog.txt';
$langfile = 'lang.php';


$log = fopen($logname, 'w');
fclose($log);

$lf = fopen($langfile, 'wb');
fwrite($lf, "rnrnt'spilt' => '---------------------------------- ------------------',");
fclose($lf);

$lf = fopen($langfile, 'ab') ;


$ptag = '\';

findfile($sf);
fwrite($lf, "rn);rnrn?>");
fclose($lf);
function findfile($sf){
global $ptag, $logname, $filter, $lf;
$log = fopen($logname, 'ab');
global $remark;
if(is_dir($sf)) {
if($dh = opendir($sf)) {

while(($file = readdir($dh) ) !== false) {
                                                                                                                                                       sf.$file) == 'dir') {
                                                                                                                                                                        ; $/', $file)) && !preg_match('/('.$filter.')/', $sf.$file)) {

                                                                                 'rb');
$buf = fread($sfp, filesize($sf.$file));
fclose($sfp);
foreach( $remark as $v) {
$data = '';
while(count($strcut = explode($v[0], $buf, 2)) > 1) {
$data .= $strcut[0];
If ($ Strcut = Explode ($ v [1], $ Strcut [1], 2) & gt; 1) {
$ buf = $ strcut [1];
} else {
                                $buf = $strcut[0];
                                break;
                            }

                        }
                        $data .= $strcut[0];
                        $buf = $data;
                    }
                    $data = $buf;
                    $lines = 0;
                    $cn = $str = '';
                    $cns = 0;
                    $ldata = "rnt'".str_replace('.', '_', $file)."' => '";
                    for($i = 0; $i < strlen($data); $i++){
                        $c = ord($data{$i});
                        if($c == 0x0A || $data{$i+1} == ''){
                            $lines++;
                            if(!empty($cn)){
                                $ldata .= "',";
                                $ldata = str_replace("rnt'".str_replace('.', '_', $file)."' => '',", '', $ldata);
                                fwrite($lf, $ldata);
                                $cn = "rn$lines:".$cn;
                                $str .= $cn;
                                $cn = '';
                                $ldata = "rnt'".str_replace('.', '_', $file)."' => '";
                            }
                        } elseif($c >= 0x81 && $c <= 0xFE) {
                            $c = ord($data{++$i});
                            if($c >= 0x40 && $c <= 0xFE) {
                                $cn .= $data{$i-1}.$data{$i};
                                $ldata .= $data{$i-1}.$data{$i};
                                while(($c = ord($data{++$i})) != 0x3C && $c != 0x0A && $c != 0x0D && $c != 0x27 && $c != 0x3E && $c != 0x3B && $c != 0x22 && $c != 0x3D && $c < 0x81) {
                                    $space .= chr($c);
                                }
                                $i--;
                                if(ord($data{$i+1}) < 0x81) {
                                    $cns++;
                                    $cn .= '$';
                                    $ldata .= "',rnt'".str_replace('.', '_', $file)."' => '";
                                } else {
                                    $cn .= $space;
                                }
                                $space = '';
                            }
                        }
                    }" ------- (Total $cns places)");
                                 echo "{$sf}$file (Total $cns places)
";
                                                                                                                                                                                                                                                                           ​ ; 🎜> fclose($log);

}
?>





http://www.bkjia.com/PHPjc/316972.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/316972.html
TechArticle

A tool that can find all Chinese characters in the source code. Just fill in the path you need to find $sf. Function 1 Find all Chinese 2 Ignore Chinese in comment statements 3 You can add files and...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn