詳細講解phpCB批量轉換的代碼示例
作者:佚名
phpCB批量轉換的程序代碼對于一個新手來說并不是很快就能寫出來的。我們在文章中給出了一個范例,希望能作為一個參考學習的對象。
我們在使用PHP語言的時候會遇到轉換圖片文件的需求。如果實現批量轉換的話,就能節約大量的時間。下面我們就為大家具體講解有關phpCB批量轉換的方法。#t#
最近需要整理一個整站的php代碼規范視圖,前幾天發現phpCB整理視圖非常好,但有個缺點是不能批量處理,使用過程中發現phpCB是一個CMD程序,馬上就想到php的system函數調用cmd,想到就做,下面是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批量轉換的使用方法:把phpCB.exe放在windows/system32/目錄下,php執行程序和要轉換的文件夾放同一級路徑,先配置$topath,然后在瀏覽器里訪問本程序,沒有結果輸出。
責任編輯:曹凱
來源:
yanglu.org