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,779
  • 3
  • 22
  • 24

1 Answers1

2

You can use XPath:

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

Here's a demo.

Ry-
  • 209,133
  • 54
  • 439
  • 449