Preg_match_all need to find <img src="...._50_50_ ...">

Discussion in 'PHP' started by 123GoToAndPlay, Sep 19, 2006.

  1. #1
    Can't get preg_match_all working

    First I use curl to get the source
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    $src = curl_exec ($ch);
    curl_close ($ch); 
    $src = ereg_replace("\n", "", $src);
    
    $find = '/<img src="*._50_50_.*"/';
    preg_match_all($find, $src, $m);
    
    $img=$m[1][0];
    
    Code (markup):
    Any suggestions??
     
    123GoToAndPlay, Sep 19, 2006 IP
  2. GuitarFix

    GuitarFix Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $find = '/<img src="([a-zA-Z0-9\/\_\-\.]+)_50_50_([a-zA-Z0-9\/\_\-\.]+)"/';
    preg_match_all($find, $src, $m);
    
    print_r ( $m );
    Code (markup):
     
    GuitarFix, Sep 19, 2006 IP
  3. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thx guitarFix,

    But I don't have the img src yet. I got more than with my code, now it returns

    Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) )

    I tested with
    
    print_r ( $m );
    		$img=$m[1][0];
    		echo "test ".$m[0][2];
    		echo $m[0][0];
    		echo $m[0][1];
    		echo $m[1][1];
    
    Code (markup):
    With no luck, Still learning preg_match_all.
     
    123GoToAndPlay, Sep 20, 2006 IP
  4. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ok found a solution

    
    $find = '/([\:a-zA-Z0-9\/\_\-\.]+)_50_50_([a-zA-Z0-9\/\_\-\.]+)"/';
    		preg_match_all($find, $src, $m);
    		
    		//print_r ( $m );
    		$img=$m[1][0];
    		$img.="_50_50_";
    		$img.=$m[2][0];
    		echo $img;//testing
    		$msg .= '<img src="'.$img.'">';
    		echo $msg;
    
    Code (markup):
    I added \: and read the array $m. About the array $m is this the right way???
     
    123GoToAndPlay, Sep 20, 2006 IP