Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 在 php 中按属性选择 xml 节点
有没有类似getElementByAttributePHP 的函数?如果不是,我该如何创建解决方法?
getElementByAttribute
例如
<div class="foo">FOO!</div>
我如何匹配该元素?
您可以使用 XPath:
$xpath = new DOMXPath($document); $results = $xpath->query("//*[@class='foo']");
这是一个演示。