将标记解析为元素树 [英] Parsing markup into element tree

查看:47
本文介绍了将标记解析为元素树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中,我需要将标记与XML或JSON不同,解析为元素树.我敢肯定,存在执行此类操作的库,但是我找不到自己的生命.找不到任何东西.

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.

问题是不是 XML或JSON;这是许多晦涩的标记,它们不存在专门的解析器.因此,我正在寻找一种可以以元素树的形式实现任何标记的通用解析器.

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.

推荐答案

您可以尝试以下操作: http://pear.php.net/package/PHP_ParserGenerator 与此: http://pear.php. net/package/PHP_LexerGenerator

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

这里还提供了一些版本的Lemon和JLex,支持发布PHP:

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/

这是 https://drupal.org/project/grammar_parser

这篇关于将标记解析为元素树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆