phpCB批量转换php文件视图

  最近需要整理一个整站的php代码规范视图,前几天发现phpCB整理视图非常好,但有个缺点是不能批量处理,使用过程中发现phpCB是一个CMD程序,马上就想到php的system函数调用cmd,想到就做,下面是phpCB批量转换的php程序:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?
header("Content-type: text/html; charset=gb2312");
 
define('ROOT_PATH', dirname(__FILE__));
 
$topath="ww"; //要格式化视图的目录名,前后都不要“/”
$path=ROOT_PATH."/".$topath;
$arr=get_all_files($path);
 
for($i=0;$i<count($arr);$i++)
{
 
	$phpext=fileext($arr[$i]);
	if($phpext=="php")
	{
		$cmd="phpCB.exe ".$arr[$i]." > ".$arr[$i].".phpCB";
		system($cmd);
		unlink($arr[$i]);
		@rename($arr[$i].".phpCB",$arr[$i]);
 
	}
 
}
 
function get_all_files($path){
    $list = array();
    foreach(glob($path . '/*') as $item){
        if(is_dir($item)){
	$list = array_merge($list , get_all_files( $item ));
        } else {
	$list[] = $item;
        }
    }
    return $list;
}
 
function fileext($filename) {
	return trim(substr(strrchr($filename, '.'), 1, 10));
}
 
?>

  使用方法:把phpCB.exe(不清楚的朋友可以看我的上篇博文:php格式化代码视图工具-phpCodeBeautifier)放在windows/system32/目录下,php执行程序和要转换的文件夹放同一级路径,先配置$topath,然后在浏览器里访问本程序,没有结果输出。

此条目发表在 PHP 分类目录,贴了 标签。将固定链接加入收藏夹。

phpCB批量转换php文件视图》有 2 条评论

  1. sjolzy 说:

    很有帮助!谢谢嘎

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">