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

Source: Internet
Author: User
A tool that can find all Chinese characters in the source code. A tool that can find all Chinese characters in the source code can be filled with the path to be searched $ sf. Function 1: Find all Chinese characters. 2. ignore the Chinese characters in the comment statement. 3. add files to be ignored and a tool to find all Chinese characters in the source code.

Enter the desired path $ sf.

Function
1. find all Chinese characters
2. ignore Chinese characters in the comment statement
3. you can add files and folders to be ignored.
4. generate a log file

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

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

The code is as follows:


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

$ Lf = fopen ($ langfile, 'AB ');


$ Ptag = '\\';

Findfile ($ sf );
Fwrite ($ lf, "\ 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 (count ($ 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! = 0x3E & $ 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. "--------------------- ($ Central in total )");
Echo "{$ sf} $ file ($ Central in total)
";
Ob_flush (); flush ();
$ Cns = 0;
}
Fwrite ($ log, $ str );
$ Str = '';
}
}
}
}
Fclose ($ log );

}
?>

Fill in the path $ sf to be searched. Function 1: Find all Chinese characters. 2. ignore the Chinese characters in the comment statement. 3. add the files to be ignored and...

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.