I have image in html. I parse it to DOMDocument and start working with it…
$doc = new DOMDocument();
$doc->loadHTML($article_header);
$imgs = $doc->getElementsByTagName('img');
foreach ($imgs as $img) {
$container = $img->parentNode;
if ($container->tagName != "a") {
$image_inside=utf8_decode($img->nodeValue);
echo "3".$image_inside;
die;
}
}
This code works fine line 3 gets image. line 6 understands that there is no “a” tag above this “img” tag, and line 8 must print out my initial image. But the thing is I only see “3” without image tag and etc…
I did inspect element and nothing is there. just “3” is coming out. Why I cannot print out image ?
You could use:
From PHP Documetation’s saveXML().
If you’re using PHP 5.3.6 you could use (from How to return outer html of DOMDocument?)
Note the caveat mentioned in the linked-to question: