Menu Home

token_name

osbo.com | PHP | Functions | token_name

Get the symbolic name of a given PHP token

Syntax

token_name ( int $id ) : string

Parameters

id

The token value.

Return

The symbolic name of the given id.

Examples

1

<?

$id = 382;

$return = token_name($id);

echo $return;

?>
T_OPEN_TAG

2

<?

$id = T_OPEN_TAG;

$return = token_name($id);

echo $return;

?>
T_OPEN_TAG

3

<?

$code = "<?
echo 'Hello';
?>";

$array = token_get_all($code);

foreach ($array as $value)
{
    if (is_array($value))
    {
        $id = $value[0];

        $return = token_name($id);

        echo $id . ": " . $return . PHP_EOL;
    }
}

?>
382: T_OPEN_TAG
385: T_WHITESPACE
324: T_ECHO
385: T_WHITESPACE
315: T_CONSTANT_ENCAPSED_STRING
385: T_WHITESPACE
384: T_CLOSE_TAG

Internal

token_get_all

External

PHP