DOMDocument读取标记属性,类 [英] DOMDocument read tag attributes, classes

查看:59
本文介绍了DOMDocument读取标记属性,类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用DOMDocument,DOMNode和其他家族的标签读取标签属性和类?

How can I read tag attributes and classes with DOMDocument, DOMNode and the rest of the family?

并且打算与HTML而不是XML一起使用。

And, intended to be working with HTML not XML.

也许为此使用任何有用的扩展/模块吗?

Maybe any useful extensions/modules to be used for this?

谢谢!

推荐答案

实际上,所有这些都在 PHP手册,因此我给出了一些提示:

Actually this is all in the PHP Manual, so I give some hints:


如何使用DOMDocument读取标签属性和类,

How can I read tag attributes and classes with DOMDocument, DOMNode and the rest of the family?

这些对象具有可用于访问属性的方法,例如 getAttribute

These objects have methods available to access attributes, like getAttribute.


而且,旨在使用HTML而不是XML。

And, intended to be working with HTML not XML.

使用 DomDocument-> loadHTML() 来加载HTML,这使其与XML处理非常相似。

Use DomDocument->loadHTML() to load HTML, this makes it very similar to XML handling.


也许为此使用任何有用的扩展/模块吗?

Maybe any useful extensions/modules to be used for this?

Dom扩展中,通常您可以使用它进行几乎所有操作,而无需添加是必要的。 XPath 也是Dom扩展的一部分。但是,有类似 QueryPath FluentDom 可能会封装更多您想要的内容,例如上课。

It's all in the Dom Extension, normally you can do pretty everything with it and no additions are necessary. XPath is part of the Dom Extension as well. However there are libraries like QueryPath or FluentDom that might encapsulate a bit more what you're looking for, e.g. for classes.

这篇关于DOMDocument读取标记属性,类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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