Collecting the default image off of a myspace profile

Discussion in 'PHP' started by Crayz, Mar 27, 2007.

  1. #1
    Hello, does anyone have a stable code for this? I need it pretty soon, as my site is being promoted and my current code isn't so stable right now, meaning some of the users that join my site won't be displayed because my code didn't get their default correctly! :(

    Thanks.
     
    Crayz, Mar 27, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    This should work.

    
    <?php
    
    function grab_main_pic($url)
    {
    	$ch = curl_init($url);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    	
    	if (preg_match('/<a\s+id="ctl00_Main_ctl00_UserBasicInformation1_hlDefaultImage"[^>]+><img\s+src="([^"]+)"/si', curl_exec($ch), $mainpic))
    	{
    		return $mainpic[1];
    	}
    	
    	return 'Failed to grab main pic.';
    }
    
    
    echo grab_main_pic('http://www.myspace.com/nicoswd'); 
    
    
    ?>
    
    PHP:
     
    nico_swd, Mar 27, 2007 IP