Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. <?php
  2. $fileStr = file_get_contents('path/to/file');
  3. $newStr = '';
  4.  
  5. $commentTokens = array(T_COMMENT);
  6.  
  7. if (defined('T_DOC_COMMENT'))
  8. $commentTokens[] = T_DOC_COMMENT; // PHP 5
  9. if (defined('T_ML_COMMENT'))
  10. $commentTokens[] = T_ML_COMMENT; // PHP 4
  11.  
  12. $tokens = token_get_all($fileStr);
  13.  
  14. foreach ($tokens as $token) {
  15. if (is_array($token)) {
  16. if (in_array($token[0], $commentTokens))
  17. continue;
  18.  
  19. $token = $token[1];
  20. }
  21.  
  22. $newStr .= $token;
  23. }
  24.  
  25. echo $newStr;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement