Speed up development with full-stack environments for every branch.

Learn More

How to get token names for a piece of code with PHP Tokenizer

Forked from How to use token_name with PHP Tokenizer.

113 Runs 519 Views 134 Copies
Saved

Saved

gtsolutions 373

gtsolutions
published 4 years ago

<pre>
    <?php
    /*
     * PHP Tokenizer - get token names for a piece of code
     */
    $code = '<?php echo "Hello"; ?>';
    //token_get_all parses the code and returns the tokens as arrays with token ID
    $tokens = token_get_all($code);
    foreach ($tokens as $key => $value)
        if (is_array($value))
            //token_name translates the token ID into token name
            echo token_name($value[0])."<br />";
        else echo $value[0]."<br />";
    ?>
</pre>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).