russelburgraymond Posted June 14, 2009 Share Posted June 14, 2009 I need help modifying this regex statement. Currently it gets all images from page up to the last """. I want the ENTIRE image LINK. $url = 'http://www.microsoft.com/'; // Fetch page $string = FetchPage($url); // Regex that extracts the images (full tag) $image_regex_src_url = '/<img[^>]*'. 'src=["|\'](.*)["|\']/Ui'; preg_match_all($image_regex, $string, $out, PREG_PATTERN_ORDER); $img_tag_array = $out[0]; echo "<pre>"; print_r($img_tag_array); echo "</pre>"; // Regex for SRC Value $image_regex_src_url = '/<img[^>]*'. 'src=["|\'](.*)["|\']/Ui'; preg_match_all($image_regex_src_url, $string, $out, PREG_PATTERN_ORDER); $images_url_array = $out[1]; echo "<pre>"; print_r($images_url_array); echo "</pre>"; // Fetch Page Function function FetchPage($path) { $file = fopen($path, "r"); if (!$file) { exit("The was a connection error!"); } $data = ''; while (!feof($file)) { // Extract the data from the file / url $data .= fgets($file, 1024); } return $data; } ?> He says it extracts the whole tag but it does not. Link to comment https://forums.phpfreaks.com/topic/162171-help-modifying-this-regex-a-little/ Share on other sites More sharing options...
pkedpker Posted June 14, 2009 Share Posted June 14, 2009 yes it only supports <img.. but there could be <IMG <iMg <ImG all kinds of patterns. Here I found a example that should support all $image_regex_src_url = '/\< *[^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)/i'; Link to comment https://forums.phpfreaks.com/topic/162171-help-modifying-this-regex-a-little/#findComment-855807 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.