Explain in detail the sample code of phpCB batch conversion

Source: Internet
Author: User

We are using

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:

  1. <?
  2. Header ("Content-type: text/html; charset = gb2312 ");
  3. Define ('root _ path', dirname (_ FILE __));
  4. $ Topath = "ww"; // The Directory Name of the view to be formatted. Do not "/"
  5. $ Path = ROOT_PATH. "/". $ topath;
  6. $ Arr = get_all_files ($ path );
  7. For ($ I = 0; $ I ($ 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. ?>

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.


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.