Jump to content

How To Use This Reg_Ex Example


medicalboy
 Share

Recommended Posts

this is a code to get all images from a certain site, i want to know how to echo output correctly

$images = array();preg_match_all('/(img|src)\=(\"|\')[^\"\'\>]+/i', $data, $media);unset($data);$data=preg_replace('/(img|src)(\"|\'|\=\"|\=\')(.*)/i',"$3",$media[0]);foreach($data as $url){$info = pathinfo($url);if (isset($info['extension'])){  if (($info['extension'] == 'jpg') ||  ($info['extension'] == 'jpeg') ||  ($info['extension'] == 'gif') ||  ($info['extension'] == 'png'))  array_push($images, $url);}}

  • Like 1
Link to comment
Share on other sites

$data in the first instance (preg_match_all) should be the markup containing the images (ie page source). media is where it will be returned. I think you mistakenly swapped those around in the described function? however after quickly looking at the code, you could doecho $url; inside the foreach function.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...