only getting <img src=''.. > i need it to get all of images where ever src was...

Discussion in 'PHP' started by free-designer, Mar 1, 2010.

  1. #1
    hello guys, again,

    i have this code that grab all imgs like that <img src='linkhere.jpg' />

    but what if the img like that <img id='imgid' height='100' width='100' src='linkhere.jpg' />

    so it not going to get it cuz the src at the end of the code so i want some one to update my code and make it just read the images in the page where ever the src was

    here is my code

    
          preg_match_all("/(<img)\s (src=\"(  [a-zA-Z0-9\.;:\/\?&=_|\r|\n]   (.*)   \.(jpg|png)  )\")/isxmU", file_get_contents($url), $images)
    
    PHP:
    thanks for anyhelp
     
    free-designer, Mar 1, 2010 IP
  2. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #2
    How about this?
    /<img[^>]*>/Ui
    Code (markup):
     
    Sky AK47, Mar 1, 2010 IP
  3. free-designer

    free-designer Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    nope it's not working after i go trough each one of them it gives me an error
     
    free-designer, Mar 1, 2010 IP
  4. free-designer

    free-designer Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    here is all of the code


    
            
    		    if(preg_match_all("/(<img)\s (src=\"(  [a-zA-Z0-9\.;:\/\?&=_|\r|\n]   (.*)   \.(jpg|png)  )\")/isxmU", file_get_contents($_SESSION['url']), $images)){
    		    
    			/* limit number of images shown */
    		    $limit = 4;
    		    $i=0;
    			foreach($images[3] as $image_url):
            	$valid_files = substr($image_url, -3);
    	        if($valid_files == "png" || $valid_files == "jpg"){
    		        if(dose_url_exists($image_url)){
    					$i++;
    					if($i == $limit) break;
    					$image_hash = md5($image_url);
    					$image_ext = substr($image_url, -3);
    			
    		?>
    		
    			<td style="float:left; margin:0 10px;"><img src="<?php echo $image_url; ?>" /></td>
    			
    		<?php  } } endforeach; ?>
    
    
    PHP:
     
    free-designer, Mar 1, 2010 IP