The sample code for batch phpCB conversion is described in detail. We recently used to sort out a full-site php code specification View. a few days ago, we found that the phpCB arrangement view was very good, but there was a drawback that it could not be processed in batches. during use, we found that we were using php.
Recently, we need to organize a full-site php code specification View. a few days ago, we found that the phpCB arrangement view is very good, but there is a drawback that it cannot be processed in batches. during use, we found that phpCB is a CMD program, the php system function calls cmd immediately. The php program for batch conversion of phpCB is as follows:
- <?
- Header ("Content-type: text/html; charset = gb2312 ");
- Define ('root _ path', dirname (_ FILE __));
- $ Topath = "ww"; // The directory name of the view to be formatted. do not "/"
- $ Path = ROOT_PATH. "/". $ topath;
- $ Arr = get_all_files ($ path );
- For ($ I = 0; $ I ($ 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 ));
- }
- ?>
How to use batch phpCB conversion: put phcmd.exe in the windows/system32/directory, put the php executable program and the folder to be converted in the same level path, first configure $ topath, then, access the program in the browser without result output.
Ghost recently needs to organize a full-site php code specification View. a few days ago, it was found that the phpCB arrangement view was very good, but one drawback was that it could not be processed in batches. php was found during use...