A _php instance of a tool that can find all the Chinese in the source code

Source: Internet
Author: User
Tags explode ord
A tool that can find all the Chinese in the source code

Fill in the path you need to find $SF.

Function
1 Find all Chinese
2 Ignore the Chinese in the comment statement
3 Add files and folders that need to be ignored
4 Generating log files

If you are worried about updating your 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 code as follows:

<?php
Set_time_limit (0);
Ob_implicit_flush ();

Annotation format
$remark = Array (
Array ('//debug ', "\ r \ n")
, Array ('/** ', ' */')
, Array ('/*debug ', ' */')
, Array ('/*note ', ' */')
, Array ('//note ', "\ r \ n")
);

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, "\r\n\r\n\t ' spilt ' => '----------------------------------------------------'");
Fclose ($LF);

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


$ptag = ' \ n ';

FindFile ($SF);
Fwrite ($LF, "\ r \ n);\r\n\r\n?>");
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) {
if ($file = = '. ' | | $file = = ' ... ') {
Continue
} elseif (FileType ($sf. $file) = = ' dir ') {
FindFile ($SF. $file. $ptag);
ElseIf (Preg_match ('/\.php$/', $file) | | preg_match ('/\.htm$/', $file)) &&!preg_match ('/('. $filter. ') /', $SF. $file)})

$SFP = fopen ($sf. $file, ' RB ');
$buf = Fread ($SFP, FileSize ($sf. $file));
Fclose ($SFP);
foreach ($remark as $v) {
$data = ';
while ($strcut = explode ($v [0], $BUF, 2)) > 1) {
$data. = $strcut [0];
if ($strcut = explode ($v [1], $strcut [1], 2)) > 1) {
$buf = $strcut [1];
} else {
$buf = $strcut [0];
Break
}

}
$data. = $strcut [0];
$buf = $data;
}
$data = $buf;
$lines = 0;
$CN = $str = ';
$cns = 0;
$ldata = "\r\n\t '". 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 ("\r\n\t". Str_replace ('. ', ' _ ', $file). "' => ', ', ', ', $ldata ';
Fwrite ($LF, $ldata);
$CN = "\r\n$lines:" $CN;
$str. = $CN;
$CN = ';
$ldata = "\r\n\t '". 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!= 0 x3e && $c!= 0x3b && $c!= 0x22 && $c!= 0x3d && $c < 0x81) {
$space. = Chr ($c);
}
$i--;
if (Ord ($data {$i +1}) < 0x81) {
$cns + +;
$cn. = ' $ ';
$ldata. = "', \r\n\t '". Str_replace ('. ', ' _ ', $file). "' => ';
} else {
$cn. = $space;
}
$space = ';
}
}
}
if ($str!= ') {
Fwrite ($log, "\n--". $sf. $file. " -----------------------(Total $cns) ");
echo "{$SF} $file (total $cns) <br>";
Ob_flush (); flush ();
$cns = 0;
}
Fwrite ($log, $STR);
$str = ';
}
}
}
}
Fclose ($log);

}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.