background image

PHP

实例 phpCB 批量转换的代码示例

我们在使用 PHP 语言的时候会遇到转换图片文件的需求。如果实现批量转换的话,就能
节约大量的时间。下面我们就为大家具体讲解有关 phpCB 批量转换的方法。
 
最近需要整理一个整站的 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