1

Possible Duplicate:
Select xml node by attribute in php

Is there any function like getElementByAttribute in PHP? If no, how do I create a workaround?

E.g.

<div class="foo">FOO!</div>

How do I match that element?

Community
  • 1
  • 1
siaooo
  • 1,827
  • 3
  • 23
  • 25

1 Answers1

2

You can use XPath:

$xpath = new DOMXPath($document);
$results = $xpath->query("//*[@class='foo']");

Here's a demo.

Ry-
  • 218,210
  • 55
  • 464
  • 476