code example for deep parsing PHPCB batch Conversions

Source: Internet
Author: User
Tags php language php code tidy

We encounter the need to convert picture files when using the PHP language. If you implement batch conversion, you can save a lot of time. Here we will give you a specific explanation about the PHPCB batch conversion method.

Recently need to tidy up a whole station of PHP code specifications view, a few days ago found PHPCB tidy view is very good, but there is a disadvantage is not batch processing, the use of the process found PHPCB is a CMD program, immediately think of PHP system function call cmd, think about doing, The following is a PHPCB batch conversion PHP Program:

Copy Code code as follows:


<?


header ("content-type:text/html; charset=gb2312 ");


define (' Root_path ', DirName (__file__));


$topath = "WW"; To format a view's directory name, do not forward or backward "/"


$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 Batch Conversion method: Put the PhpCB.exe in the windows/system32/Directory, PHP execution program and the folder to be converted to the same level of path, first configure the $topath, and then access the program in the browser, no results output.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.