- token_get_all: documentation ( source)
- str_replace: documentation ( source)
- token_name: documentation ( source)
<?php
$string = '<?php
function MyFunction1() {
// Some code goes here.
}
function MyFunction2() {
// Some code goes here.
}
class MyClass
{
function MyFunction3() {
// Some code goes here.
}
function MyFunction4() {
// Some code goes here.
}
public function register();
}
public function register();
function foo() { }
function foo() {}
function foo() {
}
function foo()
{
for ($i = 0; $i < $bar; $i++) {
}//end for
}
';
$tokens = token_get_all($string);
foreach ($tokens as $i => $token) {
echo "$i : ";
if (is_array($token) === false) {
echo $token;
} else {
echo token_name($token[0]).' => '.str_replace(PHP_EOL, '\n', $token[1]);
}
echo PHP_EOL;
}