Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created January 29, 2017 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpfiddle/cf1f0dda5d49cacb1254a61739c6bbd3 to your computer and use it in GitHub Desktop.
Save phpfiddle/cf1f0dda5d49cacb1254a61739c6bbd3 to your computer and use it in GitHub Desktop.
[ Posted by Mohammad ] get all src tag img
<?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