在属性简单的HTML DOM通配符 [英] Simple HTML DOM wildcard in attribute
问题描述
我有以下代码
<div class="col *">Text</div>
*
是什么。
我想获得的所有div标签类属性包含山坳
(在我的例子)使用的简单的HTML DOM 。
I want to get all div tag with class attribute contains col
(as in my example) using Simple HTML DOM.
推荐答案
由于简单的HTML DOM 确实已经有选择含有一定的价值和属性的方法|或别的东西。例如:
Since Simple HTML DOM does already have a method for selecting attributes that contain a certain value and|or something else. For example
$ HTML的&GT;找到(DIV [*类COL =],0) - &GT; outertext
或者你可以只检索与山坳
开始像这样 DIV
节点
Or you could just retrieve div
nodes that start with col
like so
$ HTML的&GT;找到(DIV [^类= COL],0) - &GT; outertext
和进行安全保管,你可以找到所有的其他的方式来过滤这个第三方插件属性(顺便说一句有处理DOM的方式更好的东西,是基于的libxml
,最终列表可<一个href=\"http://stackoverflow.com/questions/3577641/how-to-parse-and-process-html-with-php/3577662#3577662\">found这里)
And for safe keeping you can find all the other ways to filter attributes in this 3rd party plugin (By the way there are way better things for dealing with DOM that are based on libxml
, a definitive list can be found here)
-
[属性]
- 匹配具有特定属性的元素 -
-
[属性=值]
- 匹配有具有一定值的指定属性的元素 -
[属性=值!]
- 匹配没有具有一定值的指定属性的元素 -
[^属性值=]
- 匹配具有指定属性的元素,它具有一定的值开始 -
[属性$ =值]
- 匹配具有指定属性的元素,它具有一定的值结束 -
[属性* =值]
- 匹配具有指定属性的元素,并含有一定值
[attribute]
- Matches elements that have the specified attribute.[!attribute]
- Matches elements that don't have the specified attribute.[attribute=value]
- Matches elements that have the specified attribute with a certain value.[attribute!=value]
- Matches elements that don't have the specified attribute with a certain value.[attribute^=value]
- Matches elements that have the specified attribute and it starts with a certain value.[attribute$=value]
- Matches elements that have the specified attribute and it ends with a certain value.[attribute*=value]
- Matches elements that have the specified attribute and it contains a certain value.
来源:<一个href=\"http://simplehtmldom.sourceforge.net/manual.htm\">http://simplehtmldom.sourceforge.net/manual.htm
这篇关于在属性简单的HTML DOM通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!