PHP头条
热点:

详细讲解phpCB批量转换的代码示例


我们在使用PHP语言的时候会遇到转换图片文件的需求。如果实现批量转换的话,就能节约大量的时间。下面我们就为大家具体讲解有关phpCB批量转换的方法。

  • 初步了解PHP获取数据库表信息函数
  • PHP加入数据程序的具体实现方法
  • PHP整数取余返回负数的相关解决办法
  • 教你学会WinXP搭建PHP开发环境
  • 如何高效优化PHP代码解析损耗

最近需要整理一个整站的php代码规范视图,前几天发现phpCB整理视图非常好,但有个缺点是不能批量处理,使用过程中发现phpCB是一个CMD程序,马上就想到php的system函数调用cmd,想到就做,下面是phpCB批量转换的php程序:

  1. < ?  
  2. header("Content-type: text/html; charset=gb2312");  
  3. define('ROOT_PATH', dirname(__FILE__));  
  4. $topath="ww"; //要格式化视图的目录名,前后都不要“/”  
  5. $path=ROOT_PATH."/".$topath;  
  6. $arr=get_all_files($path);  
  7. for($i=0;$i<count($arr);$i++)  
  8. {  
  9. $phpext=fileext($arr[$i]);  
  10. if($phpext=="php")  
  11. {  
  12. $cmd="phpCB.exe ".$arr[$i]." > ".$arr[$i].".phpCB";  
  13. system($cmd);  
  14. unlink($arr[$i]);  
  15. @rename($arr[$i].".phpCB",$arr[$i]);  
  16. }  
  17. }  
  18. function get_all_files($path){  
  19. $list = array();  
  20. foreach(glob($path . '/*') as $item){  
  21. if(is_dir($item)){  
  22. $list = array_merge($list , get_all_files( $item ));  
  23. } else {  
  24. $list[] = $item;  
  25. }  
  26. }  
  27. return $list;  
  28. }  
  29. function fileext($filename) {  
  30. return trim(substr(strrchr($filename, '.'), 1, 10));  
  31. }  
  32. ?>  

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

www.phpzy.comtrue/php/13078.htmlTechArticle详细讲解phpCB批量转换的代码示例 我们在使用PHP语言的时候会遇到转换图片文件的需求。如果实现批量转换的话,就能节约大量的时间。下面我们就为大家具体讲解有关phpCB批量转换的...

相关文章

    暂无相关文章
相关频道:

PHP之友评论

今天推荐