- token_get_all: documentation ( source)
- token_name: documentation ( source)
<?php
$code = <<<EOP
<?php
function extractURL($url)
{
if (preg_match('#http://www.google.com/?$#i', $url, $match)) {
return $match[1];
}
return null;
}
EOP;
$tokens = token_get_all($code);
foreach ($tokens as $token) {
if (is_string($token)) {
print "[(string)] " . $token . "\r\n";
} else {
print "[" . token_name($token[0]) . "] " . $token[1] . "\r\n";
}
}