getElementByAttribute PHP DOM [英] getElementByAttribute PHP DOM
本文介绍了getElementByAttribute PHP DOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
在php中选择xml节点按属性
PHP中有没有像$ getElementByAttribute
这样的函数?如果没有,如何创建一个解决方法?
Is there any function like getElementByAttribute
in PHP? If no, how do I create a workaround?
例如
<div class="foo">FOO!</div>
如何匹配该元素?
推荐答案
您可以使用XPath:
You can use XPath:
$xpath = new DOMXPath($document);
$results = $xpath->query("//*[@class='foo']");
这篇关于getElementByAttribute PHP DOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文