0

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 Answer 1

1
if($elementhtml->length) echo $dom->saveXML($elementhtml->item(0));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.