詳細(xì)講解phpCB批量轉(zhuǎn)換的代碼示例
我們?cè)谑褂?a >PHP語(yǔ)言的時(shí)候會(huì)遇到轉(zhuǎn)換圖片文件的需求。如果實(shí)現(xiàn)批量轉(zhuǎn)換的話,就能節(jié)約大量的時(shí)間。下面我們就為大家具體講解有關(guān)phpCB批量轉(zhuǎn)換的方法。#t#
最近需要整理一個(gè)整站的php代碼規(guī)范視圖,前幾天發(fā)現(xiàn)phpCB整理視圖非常好,但有個(gè)缺點(diǎn)是不能批量處理,使用過(guò)程中發(fā)現(xiàn)phpCB是一個(gè)CMD程序,馬上就想到php的system函數(shù)調(diào)用cmd,想到就做,下面是phpCB批量轉(zhuǎn)換的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批量轉(zhuǎn)換的使用方法:把phpCB.exe放在windows/system32/目錄下,php執(zhí)行程序和要轉(zhuǎn)換的文件夾放同一級(jí)路徑,先配置$topath,然后在瀏覽器里訪問(wèn)本程序,沒(méi)有結(jié)果輸出。