Created
January 29, 2017 10:55
-
-
Save phpfiddle/cf1f0dda5d49cacb1254a61739c6bbd3 to your computer and use it in GitHub Desktop.
[ Posted by Mohammad ] get all src tag img
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$array = array(); | |
$question_data = ' <img class="img-responsive" src="/uploads/images/questions/93_20161017102613.jpg" style="max-height:400px;" /> | |
<img class="img-responsive" src="/uploads/images/questions/93_20161017102615.jpg" style="max-height:400px;" />'; | |
$xml = new DOMDocument(); | |
$xml->loadHTML($question_data); | |
$imgNodes = $xml->getElementsByTagName('img'); | |
for ($i = $imgNodes->length - 1; $i >= 0; $i--) : | |
$imgNode = $imgNodes->item($i); | |
$image_file_names = $imgNode->getAttribute('src'); | |
if(!empty($image_file_names)) : | |
$array[] = $image_file_names; | |
endif; | |
endfor; | |
echo '<pre>'; | |
print_r($array); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment