beingalex Posted February 16, 2010 Share Posted February 16, 2010 Hi Guys, I'm trying to use the DOMDocument to get an entire img tag (from the "<img" to the "/>"). Is this possible ? I have to get the first img tag that is found in a string of html. Here is what I have so far: $dom = new DOMDocument(); $dom->preseveWhiteSpace = FALSE; @$dom->loadHTML($post->post_content); $images = $dom->getElementsByTagName("img"); "post_content" definitely returns a string of html with an img tag in it, however all my attemps to get that tag have failed. Any help is much appreciated, thank you in advance - Alex Quote Link to comment https://forums.phpfreaks.com/topic/192246-using-document-object-model-to-get-entire-img-tag/ Share on other sites More sharing options...
salathe Posted February 16, 2010 Share Posted February 16, 2010 foreach ($images as $image) { echo $dom->saveXML($image) . PHP_EOL; } That will echo all of the image tags. Quote Link to comment https://forums.phpfreaks.com/topic/192246-using-document-object-model-to-get-entire-img-tag/#findComment-1013097 Share on other sites More sharing options...
beingalex Posted February 16, 2010 Author Share Posted February 16, 2010 Thats fantastic! Thank you salathe Quote Link to comment https://forums.phpfreaks.com/topic/192246-using-document-object-model-to-get-entire-img-tag/#findComment-1013117 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.