Parsing markup into element tree

两盒软妹~` 提交于 2019-12-12 09:39:43

问题


I need to parse markup not unlike XML or JSON into trees of elements, in PHP. I'm certain there exist libraries for doing this kind of thing, but I can't for the life of me find any.

Problem is this isn't XML or JSON; It's a number of obscure markups for which exist no specialized parsers. Thus I'm looking for a generic parser that can implement any markup in the form of an element tree.

Alternatively, articles on how to write one. I've written a recursive parser before, but am unsure how to approach making a generic, reusable one.


回答1:


You could try this: http://pear.php.net/package/PHP_ParserGenerator with this: http://pear.php.net/package/PHP_LexerGenerator

There is also some versions of Lemon and JLex with support for emitting PHP here: http://wezfurlong.org/blog/2006/nov/parser-and-lexer-generators-for-php/

And this: https://drupal.org/project/grammar_parser



来源:https://stackoverflow.com/questions/7164318/parsing-markup-into-element-tree

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!