How can I get the value of an HTML element using PHP and XPath? -


I have a whole HTML string that is being evaluated using PHPDom and it's working perfectly , Except I do not know how to do this one thing that really looks basic, I have to choose an HTML element through XPath and return the contents of that element as a string. So far, I have it. Can anyone tell me in the right direction how to move forward? Thanks!

$ dom = newdomdocument (); @ $ Dom- & gt; LoadHTML ($ theHTML); $ Xpath = new DOMXPath ($ dom); $ Elementhtml = $ xpath- & gt; Rate ('// * [[id = "elementid"]'); Var_dump ($ elementhtml); Die ();

So basically, I need $ elementhtml to have the content of the "elementid" HTML element.

  if ($ elementhtml-> length) resonates $ dom- & gt; SaveXML ($ elementhtml-> item (0));  

Comments