Jump to content

help modifying this regex a little.


Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.