W e S D
0 1

[PHP插件教程]002.代码包PHP Beautifier的使用

This program reformat and beautify PHP source code files automatically. The program is Open Source and distributed under the terms of PHP Licence. It is written in PHP 5 and has a command line tool.

PHP Beautifier是一个用php编写的php代码美化工具。

框架详细的介绍地址:http://beautifyphp.sourceforge.net/

其他相关下载:

PHP Code Beautifier下载PHP Beautifier下载

其他不多说,不讲常规安装方式,我们通过pear可以很方便的安装并使用。

下面,就让我们讲一下<如何在windows下安装PHP Beautifier?>

 

安装步骤


1.首先,确保php环境下已经安装了pear,如果没有安装请参考文章《[PHP插件教程]001.Pear包管理器》。

 

2.pear下安装PHP Beautifier

在联网环境下,CMD命令行下运行 pear install php_beautifier-0.1.15,自动下载包并安装。

正常情况下,只要出现install ok,就表示已经安装成功了 "":)

 

如何使用?


安装好后,可以在CMD命令行下运行 php_beautifier -h 查看使用说明。

接下来,我们就可以运行命令来格式化我们凌乱的代码了。

示例:

例如有一个比较凌乱且无比粗糙的foo.php文件:

<?php    error_reporting(0);function shutdown_handler(){if( $error=error_get_last() ) {  
            print_r( $error );}     }  
register_shutdown_function( 'shutdown_handler' );  
class foo{   
    public $bar='hello world!';  
    public function __construct(){} }  
echo var_export( new foo(), true );  
?>  

使用php_beautifier,执行命令:

php_beautifier -t <待格式化文件路径>\foo.php <格式化文件路径>\foo.beautiful.php

执行过程中,可能会报“Notice: Use of undefined constant T_NAMESPACE - assumed 'T_NAMESPACE' in E:\php5\PEAR\PHP\Beautifier.php on line 377”。

这是因为T_NAMESPACE这个常量是在php5.3种才有定义的,如果非5.3版本则会出现这个Notice,可以忽略,不影响代码格式化。

这个时候我们就可以看到foo.php经过格式化后的代码文件foo.beautiful.php:

<?php  
error_reporting(0);  
function shutdown_handler() {  
    if ($error = error_get_last()) {  
        print_r($error);  
    }  
}  
register_shutdown_function('shutdown_handler');  
class foo {  
    public $bar = 'hello world!';  
    public function __construct() {  
    }  
}  
echo var_export(new foo(), true);  
?>  
 
 

 

本站文章为 宝宝巴士 SD.Team 原创,转载务必在明显处注明:(作者官方网站: 宝宝巴士 
转载自【宝宝巴士SuperDo团队】 原文链接: http://www.cnblogs.com/superdo/p/4677678.html

 

posted @ 2015-07-26 14:51  SD.Team  阅读(726)  评论(0编辑  收藏  举报