一个可以找出源代码中所有中文的工具


Posted in PHP onOctober 25, 2006

一个可以找出源代码中所有中文的工具

填写需要查找的路径$sf即可。

功能
1 找出所有中文
2 忽略注释语句中的中文
3 可添加需要忽略的文件和文件夹
4 生成日志文件

如果您正发愁为自己的软件更新语言包
请使用此工具。

我的例子:
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") 
); 
//以下目录和文件不被查询 
$filter = 'forumdata|config\.inc\.php|debug|test|readme|utilities|upgrade|\.tpl.php|index\.htm|\.lang.php'; 
//项目目录 
$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); 
} 
?>
PHP 相关文章推荐
用PHP创建PDF中文文档
Oct 09 PHP
php+dbfile开发小型留言本
Oct 09 PHP
刚才在简化php的库,结果发现很多东西
Dec 31 PHP
php结合飞信 免费天气预报短信
May 07 PHP
php上传apk后自动提取apk包信息的使用(示例下载)
Apr 26 PHP
php按百分比生成缩略图的代码分享
May 10 PHP
PHP FTP操作类代码( 上传、拷贝、移动、删除文件/创建目录)
May 10 PHP
destoon二次开发模板及调用语法汇总
Jun 21 PHP
memcache一致性hash的php实现方法
Mar 05 PHP
php目录拷贝实现方法
Jul 10 PHP
php封装的图片(缩略图)处理类完整实例
Oct 19 PHP
PHP字典树(Trie树)定义与实现方法示例
Oct 09 PHP
《APMServ 5.1.2》使用图解
Oct 23 #PHP
APMServ使用说明
Oct 23 #PHP
别人整理的服务器变量:$_SERVER
Oct 20 #PHP
Apache, PHP在Windows 9x/NT下的安装与配置 (二)
Oct 09 #PHP
PHP新手上路(十)
Oct 09 #PHP
来自PHP.NET的入门教程
Oct 09 #PHP
PHP新手上路(九)
Oct 09 #PHP
You might like
Discuz! Passport 通行证整合
2008/03/27 PHP
PHP Error与Logging函数的深入理解
2013/06/03 PHP
php模拟ping命令(php exec函数的使用方法)
2013/10/25 PHP
神盾加密解密教程(一)PHP变量可用字符
2014/05/28 PHP
Symfony学习十分钟入门经典教程
2016/02/03 PHP
php生成图片缩略图功能示例
2017/02/22 PHP
document节点对象的获取方式示例介绍
2013/12/24 Javascript
深入理解javascript的执行顺序
2014/04/04 Javascript
jQuery中innerHeight()方法用法实例
2015/01/19 Javascript
jquery插件tytabs.jquery.min.js实现渐变TAB选项卡效果
2015/08/25 Javascript
基于bootstrap的文件上传控件bootstrap fileinput
2016/12/23 Javascript
基于jQuery实现瀑布流页面
2017/04/11 jQuery
浅谈Vue内置component组件的应用场景
2018/03/27 Javascript
layer.open 按钮的点击事件关闭方法
2018/08/17 Javascript
Vue.Draggable拖拽功能的配置使用方法
2020/07/29 Javascript
详解webpack编译速度提升之DllPlugin
2019/02/05 Javascript
JS前端知识点总结之页面加载事件,数组操作,DOM节点操作,循环和分支
2019/07/04 Javascript
[01:21]DOTA2周边文化主题展 神秘商店火热开售
2017/07/30 DOTA
[01:14]英雄,所敬略同——2018完美盛典宣传视频
2018/12/05 DOTA
python中requests模块的使用方法
2015/04/08 Python
Python图算法实例分析
2016/08/13 Python
python导出chrome书签到markdown文件的实例代码
2017/12/27 Python
快速了解Python相对导入
2018/01/12 Python
django一对多模型以及如何在前端实现详解
2019/07/24 Python
python实现吃苹果小游戏
2020/03/21 Python
Python爬虫实现HTTP网络请求多种实现方式
2020/06/19 Python
pytorch 常用函数 max ,eq说明
2020/06/28 Python
巴西补充剂和维生素购物网站:Natue
2019/06/17 全球购物
迪拜领先运动补剂零售品牌中文站:Sporter商城
2019/08/20 全球购物
化学实验员岗位职责
2013/12/28 职场文书
找工作求职信
2014/07/07 职场文书
学校2014重阳节活动策划方案
2014/09/16 职场文书
医院党的群众路线教育实践活动领导班子对照检查材料
2014/09/25 职场文书
施工安全员岗位职责
2015/04/11 职场文书
2015年计生工作总结范文
2015/04/24 职场文书
微软官方消息,在 2023 年 4 月 11 日之后微软将不再为 Office 2013 和 Skype for Business 2015 提供安全更新
2022/04/21 数码科技