deleet Posted July 1, 2009 Share Posted July 1, 2009 Hello everyone. I do a lot of work with PHP string processing but this latest project knocked me for a loop. I just learned a little about preg_match yesterday and haven't been really able to adapt. I'm at the point where I got rid of the error messages but I just need to wire the variables up so I get an effective answer. Here's what the original code was, give or take a few brackets. <?PHP } else { define ("profile_url","http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=" ); $full_file_path = profile_url.$rider_fid; $handle = fopen($full_file_path,"r"); if (!$handle){ echo "<p>Sorry Myspace Is Slow Try Again.\n"; $arr = 0; } else { $timeout = 300; ini_set('max_execution_time','120'); set_time_limit(120); ini_set('default_socket_timeout','120'); while($contents = fread($handle,'1024')) { $hold .= $contents; } preg_match(long long procedure); $string_ahref = $match[1]; $subjectstr = substr($string_ahref,0,350); } fclose($handle); ini_restore('max_execution_time'); ini_restore('default_socket_timeout'); $pic = $pic_url; if(empty($pic_url)) { ?> I tried to make my own version up: <?PHP define ("profile_url","http://myspace.com/" ); $rider_fid="mucklejohndotcom"; //just an example tack-on -- completed version will have user input this $full_file_path = profile_url.$rider_fid; //combine base url with user's URL $handle = fopen($full_file_path,"r"); if (!$handle){ echo "<p>Sorry, MySpace Is Slow. Please Try Again.\n"; $arr = 0; } //ARRRR!! else { $timeout = 300; ini_set('max_execution_time','120'); set_time_limit(120); ini_set('default_socket_timeout','120'); while($contents = fread($handle,'1024')) { $hold .= $contents; } $duh=preg_match("/DisplayFriendId/i",$url['$handle'],$hold,$match); // preg_match("/\bDisplayFriendId/i",$url['$handle'],$hold,$match); ? print_r($duh); $tester1 = $match[0]; $tester2 = $match[1]; // Just trying to get anything to print and it's not... echo $tester2; echo $tester1;} ?> What I was looking to do was have the code crawl the MySpace page, find "DisplayFriendId":XXXXXXX, and then extract the ID number between "Display..." and the comma, so I would be able to plug this ID into the original code, which crawled the site by user's ID number instead of MySpace URL. All I get is a 0 for results, but as far as I know, MySpace is working fine. Any help would be appreciated. I'm able to parse out the string, so I'm all set with that. Just trying to make preg_match pull the ID and understand how to retrieve the variable... Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/164404-solved-trying-to-isolate-a-myspace-user-id-with-preg_match/ Share on other sites More sharing options...
.josh Posted July 1, 2009 Share Posted July 1, 2009 Post example of actual content you are trying to regex, including a line or 2 before and after the ID Quote Link to comment https://forums.phpfreaks.com/topic/164404-solved-trying-to-isolate-a-myspace-user-id-with-preg_match/#findComment-867232 Share on other sites More sharing options...
deleet Posted July 1, 2009 Author Share Posted July 1, 2009 MySpaceRes.Header = {"Cancel":"Cancel / Cancelación","Continue":"Continue / Continuar"}; MySpace.ClientContext = {"UserId":-1,"DisplayFriendId":10751728,"IsLoggedIn":false,"FunctionalContext":"UserViewProfile","UserType":1}; MySpace.StaticContentBase='http://x.myspacecdn.com'; MySpace.ClientMaintenanceConfigs = Quote Link to comment https://forums.phpfreaks.com/topic/164404-solved-trying-to-isolate-a-myspace-user-id-with-preg_match/#findComment-867338 Share on other sites More sharing options...
.josh Posted July 1, 2009 Share Posted July 1, 2009 // example of the content... $string = <<<CONTENT MySpaceRes.Header = {"Cancel":"Cancel / Cancelación","Continue":"Continue / Continuar"}; MySpace.ClientContext = {"UserId":-1,"DisplayFriendId":10751728,"IsLoggedIn":false,"FunctionalContext":"UserViewProfile","UserType":1}; MySpace.StaticContentBase='http://x.myspacecdn.com'; MySpace.ClientMaintenanceConfigs = CONTENT; preg_match('~"DisplayFriendId"\d+),~i',$string,$match); echo $match[1]; Quote Link to comment https://forums.phpfreaks.com/topic/164404-solved-trying-to-isolate-a-myspace-user-id-with-preg_match/#findComment-867346 Share on other sites More sharing options...
deleet Posted July 1, 2009 Author Share Posted July 1, 2009 Thanks so much, I appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/164404-solved-trying-to-isolate-a-myspace-user-id-with-preg_match/#findComment-867363 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.