格式化php代码的两种方法 24 March 2010 20:57 Wednesday by 小屋 分享收藏

 

本文来自小屋sjolzy.cn【原创】

 

1/     组装 phpCodeBeautifier + Emeditor (详细见:php格式化代码+Emeditor 太爽了

下载phpCB.exe(下载地址:http://www.waterproof.fr/products/phpCodeBeautifier/

使用Emeditor扩展外部工具:工具->打开外部工具->自定义工具->新建
标题,php代码格式化
命令,点击浏览,找到phpCB.exe的路径
参数,"$(Path)" 
初始目录,不填 
图标,随便
保存文件,可打勾可不打
使用输出栏,打上勾
之后打开php文件 就能选工具里的php代码格式化,就会输出格式化后的代码。再保存一下。

 

2/    phpCB批量转换的php程序(详细见:phpCB批量转换php文件视图/)

 

phpCB批量转换的php程序:
<?
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放在windows/system32/目录下,php执行程序和要转换的文件夹放同一级路径,先配置$topath,然后在浏览器里访问本程序,没有结果输出。

作者: Sjolzy

--EOF--

引用地址:

发表评论:

  给 “格式化php代码的两种方法” 评分

广告、无意义的评论必删!