Get all images from a HTML document


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $images = array();
  2. preg_match_all('/(img|src)=("|')[^"'>]+/i', $data, $media);
  3. unset($data);
  4. $data=preg_replace('/(img|src)("|'|="|=')(.*)/i',"$3",$media[0]);
  5. foreach($data as $url)
  6. {
  7. $info = pathinfo($url);
  8. if (isset($info['extension']))
  9. {
  10. if (($info['extension'] == 'jpg') ||
  11. ($info['extension'] == 'jpeg') ||
  12. ($info['extension'] == 'gif') ||
  13. ($info['extension'] == 'png'))
  14. array_push($images, $url);
  15. }
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.