What are some practical uses of PHP tokenizer?

后端 未结 8 997
暖寄归人
暖寄归人 2021-02-02 11:25

What are practical and day-to-day usage examples of PHP Tokenizer ?

Has anyone used this?

8条回答
  •  囚心锁ツ
    2021-02-02 11:44

    A pretty basic use is for syntax highlighting.

    foreach(token_get_all($source) as $token) {
        if (is_array($token))
        {
            $map = "token_name";
            echo "$token[1]";
        }
        else {
            echo "$token";
        }
    }
    

    The token numbers are usually converted into nicer CSS class names of course, but you could just craft a stylesheet with only .T_COMMENT, .T_ARRAY, .T_ELSEIF, .T_FUNCTION ... classes.

提交回复
热议问题