- token_get_all: documentation ( source)
- str_replace: documentation ( source)
- token_name: documentation ( source)
<?php
$string = '<?php
array(
\'one\' => \'hello\', \'two\' => "hello",
\'three\' => array(1,2,3), \'four\' => $asset->delete(),
);
';
$string = 'array(); ';
$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;
}