Advertisement
scriptz-team

[PHP] REMOVE ALL COMMENTS

May 12th, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. <?php
  2. /*
  3. _____ _____ _ _____ _____ _____ _____ _____ _____
  4. ___| | __ |_| _ |_ _|___ ___|_ _| __| _ | |
  5. |_ -| --| -| | __| | | |- _|___| | | | __| | | | |
  6. |___|_____|__|__|_|__| |_| |___| |_| |_____|__|__|_|_|_|
  7. |s C R i P T z - T E A M . i N F O|
  8. */
  9.  
  10. function remove_comments($id)
  11. {
  12. if (file_exists($id)) {
  13. if (is_dir($id)) {
  14. $h = opendir($id);
  15. while ($f = readdir($h)) {
  16. if (($f != ".") && ($f != "..")) {
  17. remove_comments($id . "/" . $f);
  18. }
  19. }
  20. closedir($h);
  21. } else if ((is_file($id)) && (end(explode('.', $id)) == "php")) {
  22. if (!is_writable($id)) {
  23. chmod($id, 0777);
  24. }
  25. if (is_writable($id)) {
  26. $f_Str = file_get_contents($id);
  27. $newStr = '';
  28. $cT = array(
  29. T_COMMENT
  30. );
  31. if (defined('T_DOC_COMMENT')) {
  32. $cT[] = T_DOC_COMMENT;
  33. }
  34. if (defined('T_ML_COMMENT')) {
  35. $cT[] = T_ML_COMMENT;
  36. }
  37. $tkns = tkn_get_all($f_Str);
  38. foreach ($tkns as $tkn) {
  39. if (is_array($tkn)) {
  40. if (in_array($tkn[0], $cT)) {
  41. continue;
  42. }
  43. $tkn = $tkn[1];
  44. }
  45. $newStr .= $tkn;
  46. }
  47. if (!file_put_contents($id, $newStr)) {
  48. $open = fopen($id, "w");
  49. fwrite($open, $newStr);
  50. fclose($open);
  51. }
  52. }
  53. }
  54. }
  55. }
  56.  
  57. remove_comments("./DIR/");
  58. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement