I have a PHP script that is supposed to read an HTML file and then return the contents of the first <h1>
tag that it finds. I do not want to use regex or the Simple HTML DOM Parser please - just plain, easy PHP.
This is my code thus far:
$document = new DOMDocument();
$document->loadHTMLFile($post_url);
$matches = $document->getElementsByTagName('h1');
$first_h1 = $matches->item(0);
echo $first_h1;
However, when I run the code, I get an error that says PHP Catchable fatal error: Object of class DOMElement could not be converted to string
Can anyone help me with where I am going wrong?
Thanks in advance!
SOLUTION: Replacing the last line with echo $first_h1->nodeValue;
seems to do the trick.