PHP_Beautifier 安裝與使用

Posted on 2008-01-30 10:49:45 by darkhero

最近都在找一些可以讓程式碼好看,讓文件好作,讓事情變得輕鬆愉快的套件或是模組。

記得前一陣子在 讓程式碼好看些 - PHP_Beautifier 有看到 PHP_Beautifier 所以就拿來玩玩看囉!
發現真是個很有趣很不錯的東西,安裝後可以直接在 shell 中將程式碼統一格式,是非常方便又實用的一個套件。

系統需求?

PHP_Beautifier 需要在 php5 的環境下執行!

但是,可以處理的是 php3, php4, php5 的檔案,基本上他是對排版作調整,並不會去調整語法。

安裝方式?

使用 pear 安裝

先確認 pear 的 channel 都更新了..

pear update-channels

然後直接使用 pear install 安裝,這裡要注意的是 PHP_Beautifier 目前還是 beta 版..

pear install PHP_Beautifier-beta

若是正式版的話只要 pear install PHP_Beautifier 即可.

接下來程式會跑跑跑,自動下載相依的 pear 模組,然後就會安裝完成.(意想不到的簡單吧!)

如何使用?

由於他會自動多一個 php_beautifier 的 shell script 在 /usr/bin 中,所以只要直接執行 php_beautifier 就好囉!

先來看一下他的 help

php_beautifier --help

Usage: php_beautifier [options] <infile> <out>
         <infile> and/or <out> can be '-', which means stdin/stdout.
         you can use ? and * for batch processing
         <out> can be a dir (ending with '/' or a real dir)
               or a file (without '/')
         multiple ins and one out = merge all files in one output
Options:
     --input             or -f <file>    input file  - default: stdin
     --output            or -o <out>     output dir or file - default: stdout
     --indent_tabs       or -t <int>     indent with tabs
     --indent_spaces     or -s <int>     indent with spaces - default
     --filters           or -l <fil_def> Add filter(s)
     --directory_filters or -d <path>    Include dirs for filters
     --compress          or -c <type>    Compress output
     --recursive         or -r           Search in subdir recursively
     --help              or -?           display help/usage (this message)

Filter definition:
     --filters "Filter1(setting1=value1,setting2=value2) Filter2()"
 

執行的時候通常看你自己的習慣是什麼,通常主要是 -t -s 兩個要選一個用,預設使用的是 -s 也就是所有的縮排都是用『空白』,而 -t 則就是縮排用的是『TAB』

另外會用到的通常還有 -r 這個遞迴參數,這樣才能同時連子目錄下面的一起處理。

你可以這樣試試

php_beautifier -t -r mylibs/* new_mylibs/

這樣就會把 mylibs 底下所有的檔案進行一次 php_beautifier 並且輸出到 new_mylibs 下。

Tags: 電腦網路 PHP+MySQL PHP網站建構

加入書籤: 收藏這篇文章到HEMiDEMi

迴響

關於phpBB3的設定問題 Post By PureWhite at 2008-04-13 01:15:56
ㄚ凱大大你好
最近我開始想玩PHPBB
可是卻在這個位置卡住了
那麼多空格我不知道要填什麼ㄟ
http://img185.imageshack.us/img185/5562/phpbb308vx6.png
http://phpbb-tw.net/phpbb/viewtopic.php?f=116&t=50303

資料庫類型: _______________________________________
資料庫伺服器地址, 或 DSN: ________________________
資料庫伺服器連接埠: _______________________________
資料庫名稱: _______________________________________
資料庫管理員名稱: _________________________________
資料庫密碼: _______________________________________
為資料庫中的資料表名稱加入字首: __________________

麻煩ㄚ凱大大協助 萬分感激

PureWhite
問主機商吧... Post By ㄚ凱 at 2008-04-30 13:02:57
這些資訊都請你直接問你的虛擬主機商吧...

或是你根本不了解 phpbb?.. 或許你多看看 phpbb-tw.net 的文章比較好吧...

我要留言!

捌 加 參 等於