tokenizer.php 631 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. if(!extension_loaded('tokenizer')) {
  3. dl('tokenizer.so');
  4. }
  5. $fp = fopen('php://stdin', 'r');
  6. while (!feof($fp)) {
  7. $content .= fread($fp, 4096);
  8. }
  9. fclose($fp);
  10. $tokens = token_get_all($content);
  11. $count = count($tokens);
  12. $state = 0;
  13. for ($i = 0; $i < $count; $i++) {
  14. $token = $tokens[$i];
  15. if (is_array($token)) {
  16. if ($state == 1 && $token[0] == T_STRING) {
  17. $token[1] = preg_replace('!([a-z])([A-Z])!e', '"$1_".strtolower("$2")', $token[1]);
  18. $state = 0;
  19. } else if ($token[0] == T_FUNCTION) {
  20. $state = 1;
  21. }
  22. $chunk = $token[1];
  23. } else {
  24. $chunk = $token;
  25. }
  26. $output .= $chunk;
  27. }
  28. print $output;
  29. ?>