Posted By

jnbn on 10/11/09


Tagged

Expression phpimagegetregexpregular


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

aleksanderek


Get all images from a HTML document


 / Published in: PHP
 

  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  

You need to login to post a comment.