Parsing and Printing PHP Code

后端 未结 3 1321
南旧
南旧 2021-01-22 05:44

Preferably I\'d like a solution which allows me to parse PHP from PHP, but any solution is welcome. (As an example of what I\'m looking for, Ruby has the - amongst othe

3条回答
  •  轮回少年
    2021-01-22 06:42

    A tokenizer is not the same as a parser. The tokenizer just produces tokens and not in a tree format. For those who are actually looking to produce an AST for PHP similar to what ruby_parser does for Ruby, use the PHP-Parser project (https://github.com/nikic/PHP-Parser).

    The PHP-Parser project also comes with a pretty printer that turns your AST back to PHP.

提交回复
热议问题