PHP代碼格式化(EditPlus+PHPCB) 支持批量格式化
發(fā)布時間:2012-12-05 23:36:55 作者:佚名
我要評論
有時候有網(wǎng)上拷貝的源碼,代碼沒有格式化,閱讀起來比較費勁,那么就需要這個工具了
DW_CS4居然只會格式化HTML和CSS代碼,G來G去也只有PHPCB這一個N久沒更新過的經(jīng)典PHP代碼格式工具了,命令行的,用法“phpcb file.php > newfile.php”。
PHPCB(PHP Code Beautifier),整合不到DW里,DW里也沒有格式化PHP代碼的功能或插件,不過PHPCB可以整合到EditPlus上,方法:
PHPCB下載地址 http://www.dbjr.com.cn/softs/23113.html
整合PHPCB到EditPlus:
EidtPlus:工具》配置用戶工具…》添加工具:
菜單文本:PHPCB
命令:瀏覽到PHPCB程序。
參數(shù):--space-after-if --optimize-eol --space-after-switch --space-after-while --space-before-start-angle-bracket --space-after-end-angle-bracket --extra-padding-for-case-statement --glue-amperscore --change-shell-comment-to-double-slashes-comment --indent-with-tab --force-large-php-code-tag --force-true-false-null-contant-lowercase --comment-rendering-style PEAR --equal-align-position 50 --padding-char-count 1 "$(FilePath)"
初始目錄:$(FileDir)
打勾:“以文本篩選器運行”,下拉選擇“替換”
“應(yīng)用”按鈕。
另外,只想更好地使用PHPCB的話,提供一個操作批處理:
操作PHPCB的一個批處理phpformat.bat:
:: 此文件的核心為 PHPCB 程序,PHPCB是一個格式化PHP代碼的軟件。
:: PHPCB的語法為: phpcb file.php > newfile.php
:: 本文件的用法為:phpf file.php
:: 本文件交給phpcb的命令為:phpcb file.php > file.php.formated.php
:: 本文件把文件交給PHPDB格式化后會打開格式化后的文件(用系統(tǒng)默認的程序)。
@echo off
setlocal
::是否提供格式化文件
if "%1" == "" goto noFile::文件是否存在
set fileName=%1
if /i not exist %fileName% set fileName=%fileName%.php
if /i not exist %fileName% goto noFile::文件類型是否正確
set ext=%fileName:~-4,4%
if /i not "%ext%" == ".php" goto extError::開始格式化,并打開
phpcb %fileName% > %fileName%.formated.php && start %fileName%.formated.php
goto end::輸出錯誤信息
:extError
echo Wrong: File Type Error
echo Usage: phpf file.php
goto end:noFile
echo Wrong: File not found
echo Usage: phpf file.php:end
<完>
PHPCB(PHP Code Beautifier),整合不到DW里,DW里也沒有格式化PHP代碼的功能或插件,不過PHPCB可以整合到EditPlus上,方法:
PHPCB下載地址 http://www.dbjr.com.cn/softs/23113.html
整合PHPCB到EditPlus:
EidtPlus:工具》配置用戶工具…》添加工具:
菜單文本:PHPCB
命令:瀏覽到PHPCB程序。
參數(shù):--space-after-if --optimize-eol --space-after-switch --space-after-while --space-before-start-angle-bracket --space-after-end-angle-bracket --extra-padding-for-case-statement --glue-amperscore --change-shell-comment-to-double-slashes-comment --indent-with-tab --force-large-php-code-tag --force-true-false-null-contant-lowercase --comment-rendering-style PEAR --equal-align-position 50 --padding-char-count 1 "$(FilePath)"
初始目錄:$(FileDir)
打勾:“以文本篩選器運行”,下拉選擇“替換”
“應(yīng)用”按鈕。
另外,只想更好地使用PHPCB的話,提供一個操作批處理:
操作PHPCB的一個批處理phpformat.bat:
復(fù)制代碼
代碼如下::: 此文件的核心為 PHPCB 程序,PHPCB是一個格式化PHP代碼的軟件。
:: PHPCB的語法為: phpcb file.php > newfile.php
:: 本文件的用法為:phpf file.php
:: 本文件交給phpcb的命令為:phpcb file.php > file.php.formated.php
:: 本文件把文件交給PHPDB格式化后會打開格式化后的文件(用系統(tǒng)默認的程序)。
@echo off
setlocal
::是否提供格式化文件
if "%1" == "" goto noFile::文件是否存在
set fileName=%1
if /i not exist %fileName% set fileName=%fileName%.php
if /i not exist %fileName% goto noFile::文件類型是否正確
set ext=%fileName:~-4,4%
if /i not "%ext%" == ".php" goto extError::開始格式化,并打開
phpcb %fileName% > %fileName%.formated.php && start %fileName%.formated.php
goto end::輸出錯誤信息
:extError
echo Wrong: File Type Error
echo Usage: phpf file.php
goto end:noFile
echo Wrong: File not found
echo Usage: phpf file.php:end
<完>
相關(guān)文章

WebStorm如何調(diào)試Vue項目? webstorm配置vue開發(fā)環(huán)境指南
WebStorm 支持多種調(diào)試工具,包括瀏覽器的開發(fā)者工具,但本文主要講解的是使用 WebStorm 自帶的調(diào)試功能2025-04-15
VSCode和webstorm怎么設(shè)置綠色護眼背景? 綠豆沙背景色的設(shè)置方法
護眼色一定程度能保護眼睛,緩解疲勞,VSCode和webstorm這兩款常用的軟件怎么設(shè)置護眼色呢?詳細請看下文介紹2025-04-15
WebStorm本身已經(jīng)足夠強大,但一些優(yōu)秀的插件能錦上添花,顯著提升開發(fā)效率,詳細請看下文介紹2025-04-15
如何安裝配置WebStorm? WebStorm安裝與使用全方位指南
WebStorm軟件在前端和后端開發(fā)領(lǐng)域都備受青睞,很多朋友不知道該怎么下載安裝,下面我們就來看看詳細的安裝配置教程2025-04-15
Webstorm怎么配置? Webstorm入門之軟件配置教程
WebStorm是一款功能強大的集成開發(fā)環(huán)境(IDE),支持各種前端開發(fā)技術(shù),今天我們就來看看Webstorm的配置教程2025-04-15
Webstorm怎么設(shè)置字體大小/背景顏色/背景圖片?
WebStorm 允許您自定義界面顏色,以創(chuàng)建更個性化和美觀的工作空間,今天我們就來看看Webstorm改變字體大小、背景顏色、設(shè)置背景圖片的方法2025-04-15
VScode上安裝PlatformIO插件能成功安裝,嘗試卸載VScode并刪除插件,這些錯誤仍然存在,下面我們就來看看這個問題的解決辦法2025-04-03
提升代碼搜索效率! VSCode里DeepSeek插件安裝與配置指南
今天我們將向大家介紹如何在Visual Studio Code中安裝并配置 DeepSeek 插件,幫助你更高效地進行代碼搜索2025-04-07
VSCode是一款免費且開源的代碼編輯器,因其強大的功能和良好的用戶體驗而廣受歡迎,本文將詳細介紹 VSCode 的基本使用方法,并通過插圖幫助你更好地理解2025-04-03
今天我們來聊聊如何安裝和配置VS Code,讓它成為你編程路上的得力助手,這個過程其實很簡單,只要跟著我的步驟走,你絕對能搞定2025-04-03





