tags:

views:

20

answers:

1

I have a whole HTML string that is being evaluated using PHPDom and it's working perfectly, except I don't know how to do this one thing that seems really basic. I need to select an HTML element via XPath and have that element's content returned as a string. So far, this is what I have. Can anyone point me in the right direction as to how to proceed? Thank you!

$dom = new DOMDocument();
@$dom->loadHTML($thehtml);
$xpath = new DOMXPath($dom);
$elementhtml = $xpath->evaluate('//*[@id="elementid"]');
var_dump($elementhtml);
die();

So basically, I need $elementhtml to be the contents of the "elementid" HTML element.

+1  A: 
if($elementhtml->length) echo $dom->saveXML($elementhtml->item(0));
Wrikken