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