深入解析phpCB批量转换的代码示例

yipeiwu_com6年前PHP代码库
我们在使用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; 

function fileext($filename) { 
return trim(substr(strrchr($filename, '.'), 1, 10)); 

?> 

phpCB批量转换的使用方法:把phpCB.exe放在windows/system32/目录下,php执行程序和要转换的文件夹放同一级路径,先配置$topath,然后在浏览器里访问本程序,没有结果输出。

相关文章

PHP中fwrite与file_put_contents性能测试代码

function microtimeFloat() {    list($usec,$sec) = explode(" ", microtime());&n...

PHP内存缓存Memcached类实例

本文实例讲述了PHP内存缓存Memcached类。分享给大家供大家参考。 具体实现方法如下: 复制代码 代码如下:<?PHP class MemcacheModel {...

redis 队列操作的例子(php)

入队操作 复制代码 代码如下: <?php $redis = new Redis(); $redis->connect('127.0.0.1',6379); while(Tr...

PHP生成图像验证码的方法小结(2种方法)

本文实例讲述了PHP生成图像验证码的方法。分享给大家供大家参考,具体如下: 1、生成加法运算验证码图片 session_start (); /*定义头文件为图片*/ header("...

解析PayPal支付接口的PHP开发方式

申请PayPal注册网址:https://www.paypal.com/ paypal接口与其它接口有些不同,稍微复杂一点。 其实银行接口也算是一个站点的插件。 所谓paypal ip...