如何“读取” PHP中的HTML文档? [英] How to "read" a HTML document in PHP?

查看:94
本文介绍了如何“读取” PHP中的HTML文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在很长一段时间里面临着一个问题。不幸的是,我无法自己找到解决方案,所以我必须在这里发布我的问题。



我写了一个小小的php脚本,它创建一个PDF文件一个动态创建的HTML文件。



现在我想要解析html文件,并且做一个动作,让下一个HTML中的标签成为瘾。 b
$ b

< div>< p>测试< / p>< / div>



我的脚本应该认识到:

第一个标记是一个div:do函数对于div
第二个标签是ap:为p做功能

我不知道我应该搜索什么。常用表达? HTML解析器?



感谢提示! 试试看XML解析器。在PHP中, SimpleXML 可能是您正在寻找的。

I'm facing a problem for a quite long time. Unfortunately I was not able to find the solution by my own, so I have to post my question here.

I am writting a little php script that creates a PDF file from a dynamically created HTML file.

Now I want to "parse" the html file and do a action in addiction to which tag is next in HTML.

E.g.

<div><p>Test</p></div>

My script should recognize:

First tag is a div: do function for div Second tag is a p: do function for p

I don't know for what I should search. Regular expressions? HTML parser?

Thanks for a hint!

解决方案

Try an XML parser. In PHP the SimpleXML is probably what you are looking for.

这篇关于如何“读取” PHP中的HTML文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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