Getting All Picture URLS in a page

Discussion in 'PHP' started by SNaRe, Sep 18, 2007.

  1. #1
    How can i get all picture urls in a page with php. I think we can make it with php but i couldn't do it
     
    SNaRe, Sep 18, 2007 IP
  2. xemiterx

    xemiterx Peon

    Messages:
    62
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    How about this:

    <?PHP
    
    	$page = file_get_contents('a.txt');
    
    	$img_ext[] = 'gif';
    	$img_ext[] = 'png';
    	$img_ext[] = 'jpg';
    	$img_ext[] = 'jpeg';
    	$img_ext[] = 'bmp';
    
    	preg_match_all("|src\=([\"'`])(.+?)\\1|i", $page, &$matches);
    	foreach ($matches[2] as $val) {
    		$file = basename($val);
    		$split_file = split('\.', $file);
    		if (in_array($split_file[1], $img_ext)) $image_array[] = $val;
    	}
    	
    	echo '<pre>';
    	print_r($image_array);
    	echo '</pre>';
    
    ?>
    PHP:
     
    xemiterx, Sep 18, 2007 IP
  3. SNaRe

    SNaRe Well-Known Member

    Messages:
    1,132
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    165
    #3
    This is what i want thank you very much
     
    SNaRe, Sep 18, 2007 IP