Jason
Jason

Reputation: 15378

How to use DOM XML to pass html and find a span

I have some html input from the user, I want to find all occurences of

<span class="widget-tag"></span>

This is what I have so far:

$d = new DOMDocument();
$d->loadHTML($html);

I don't know which function to use next.

Any help would be great.

Thanks

Jason

Upvotes: 0

Views: 158

Answers (1)

Morgan ARR Allen
Morgan ARR Allen

Reputation: 10678

After that try...

$xpath = new DOMXpath($d);
$elements = $xpath->query("//div[class='widget-tag']");

This will return a DOMNodeList of the matching elements.

Upvotes: 2

Related Questions