如何“读取” PHP中的HTML文档? [英] How to "read" a HTML document in PHP?
问题描述
我写了一个小小的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屋!