一個(gè)可以找出源代碼中所有中文的工具
更新時(shí)間:2006年10月25日 00:00:00 作者:
一個(gè)可以找出源代碼中所有中文的工具
填寫(xiě)需要查找的路徑$sf即可。
功能
1 找出所有中文
2 忽略注釋語(yǔ)句中的中文
3 可添加需要忽略的文件和文件夾
4 生成日志文件
如果您正發(fā)愁為自己的軟件更新語(yǔ)言包
請(qǐng)使用此工具。
我的例子:
http://127.0.0.1/tools/searchcn.php
http://127.0.0.1/tools/cnlog.txt
<?php
set_time_limit(0);
ob_implicit_flush();
//注釋格式
$remark = array(
array('//debug', "\r\n")
, array('/**', '*/')
, array('/*debug', '*/')
, array('/*note', '*/')
, array('//note', "\r\n")
);
//以下目錄和文件不被查詢(xún)
$filter = 'forumdata|config\.inc\.php|debug|test|readme|utilities|upgrade|\.tpl.php|index\.htm|\.lang.php';
//項(xiàng)目目錄
$sf = 'd:\\data\\labs\\develop\\dzhead\\';
//日志目錄
$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 = '\\';
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(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."----------------------- (共 $cns 處)");
echo "{$sf}$file (共 $cns 處)<br>";
ob_flush();flush();
$cns = 0;
}
fwrite($log, $str);
$str = '';
}
}
}
}
fclose($log);
}
?>
填寫(xiě)需要查找的路徑$sf即可。
功能
1 找出所有中文
2 忽略注釋語(yǔ)句中的中文
3 可添加需要忽略的文件和文件夾
4 生成日志文件
如果您正發(fā)愁為自己的軟件更新語(yǔ)言包
請(qǐng)使用此工具。
我的例子:
http://127.0.0.1/tools/searchcn.php
http://127.0.0.1/tools/cnlog.txt
復(fù)制代碼 代碼如下:
<?php
set_time_limit(0);
ob_implicit_flush();
//注釋格式
$remark = array(
array('//debug', "\r\n")
, array('/**', '*/')
, array('/*debug', '*/')
, array('/*note', '*/')
, array('//note', "\r\n")
);
//以下目錄和文件不被查詢(xún)
$filter = 'forumdata|config\.inc\.php|debug|test|readme|utilities|upgrade|\.tpl.php|index\.htm|\.lang.php';
//項(xiàng)目目錄
$sf = 'd:\\data\\labs\\develop\\dzhead\\';
//日志目錄
$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 = '\\';
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(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."----------------------- (共 $cns 處)");
echo "{$sf}$file (共 $cns 處)<br>";
ob_flush();flush();
$cns = 0;
}
fwrite($log, $str);
$str = '';
}
}
}
}
fclose($log);
}
?>
相關(guān)文章
基于PHP讀取TXT文件向數(shù)據(jù)庫(kù)導(dǎo)入海量數(shù)據(jù)的方法
本篇文章小編為大家介紹,基于PHP讀取TXT文件向數(shù)據(jù)庫(kù)導(dǎo)入海量數(shù)據(jù)的方法。需要的朋友參考下2013-04-04
PHP基于ip2long實(shí)現(xiàn)IP轉(zhuǎn)換整形
這篇文章主要介紹了PHP基于ip2long實(shí)現(xiàn)IP轉(zhuǎn)換整形,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-12-12
Laravel登錄失敗次數(shù)限制的實(shí)現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于Laravel登錄失敗次數(shù)限制的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08
Laravel5.5 動(dòng)態(tài)切換多語(yǔ)言的操作方式
今天小編就為大家分享一篇Laravel5.5 動(dòng)態(tài)切換多語(yǔ)言的操作方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-10-10
使用 PHPMAILER 發(fā)送郵件實(shí)例應(yīng)用
以前的mail(),已經(jīng)不在流行,所以放上最近用的實(shí)例,留做回憶;需要的朋友可以參考下2012-11-11

