gamefreak13 Posted May 22, 2008 Share Posted May 22, 2008 I don't know what to title this. I have $sometext = "site.com/viewprofile.cfm?blah=yay&friendid=12828&mytoken=dsf22d23d"; I need to take $sometext and delete EVERYTHING before the equal sign after friendid... AND.. everything after the number 12828.. thus leaving only the number 12828 (which changes depending on the setting of $sometext). The result (remove red, keep green): $sometext = "site.com/viewprofile.cfm?blah=yay&friendid=12828&mytoken=dsf22d23d"; Which means.. $sometext = "12828"; How do I do this with PHP? Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/ Share on other sites More sharing options...
peranha Posted May 22, 2008 Share Posted May 22, 2008 Is this in the url Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-547069 Share on other sites More sharing options...
samuraitux Posted May 22, 2008 Share Posted May 22, 2008 note sure if this is right but you can take $sometext = $_REQUEST['friendid'] and that should give $sometext the value of 1282. However this will only work if site.com/viewprofile.cfm?blah=yay&friendid=12828&mytoken=dsf22d23d is being passed through the url and not actually assigned to $sometext in teh first place. Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-547071 Share on other sites More sharing options...
peranha Posted May 22, 2008 Share Posted May 22, 2008 $sometext = $_GET['friendid']; That would be if it is in the url, but not if passed through a form. Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-547073 Share on other sites More sharing options...
gamefreak13 Posted May 22, 2008 Author Share Posted May 22, 2008 Everyone replied with the same answer on Yahoo Answers.. uggh (although I do understand the confusion). Do not look at it like its a url... imagine its just text. Somesite.com is not my site. It is the referrer to a php script of mine. Now, the referer is just text.. ignore that its a url. Now.. I need to rip just the number of friendid. How do I do that? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-547075 Share on other sites More sharing options...
peranha Posted May 22, 2008 Share Posted May 22, 2008 Is there always 3 variables blah=yay friendid=12828 mytoken=dsf22d23d Or do they change amounts Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-547076 Share on other sites More sharing options...
gamefreak13 Posted May 22, 2008 Author Share Posted May 22, 2008 The amounts always change.. which is why this is so difficult. I believe I need to do something like substr (I think it the proper code) and tell it to delete things like mysite.com and viewprofile.cfm and all question marks.. etc.. but that seems so sloppy. I would think there has to be a way to be like "hey php, see this variable in this text? Give it to me.". Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-547080 Share on other sites More sharing options...
sasa Posted May 22, 2008 Share Posted May 22, 2008 if $sometext isn't url try <?php $sometext = "site.com/viewprofile.cfm?blah=yay&friendid=12828&mytoken=dsf22d23d"; preg_match('/friendid=([^&]*)/',$sometext,$out); $friendid = $out[1]; echo $friendid; ?> Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-547081 Share on other sites More sharing options...
peranha Posted May 22, 2008 Share Posted May 22, 2008 if $sometext isn't url try <?php $sometext = "site.com/viewprofile.cfm?blah=yay&friendid=12828&mytoken=dsf22d23d"; preg_match('/friendid=([^&]*)/',$sometext,$out); $friendid = $out[1]; echo $friendid; ?> I really should learn regex it looks like Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-547082 Share on other sites More sharing options...
gamefreak13 Posted May 22, 2008 Author Share Posted May 22, 2008 OMG Thank you!!!!!! That is EXACTLY what I needed!!! *celebrates* Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-547084 Share on other sites More sharing options...
gamefreak13 Posted May 22, 2008 Author Share Posted May 22, 2008 Ok one little problem.. what if friendid is written as friendID or FriendID... it doesnt work.. its matching the case of all lowercase. I think there is a function called lower or lwr or something that will change it to lowercase before "searching" so-to-speak... or is there an easier/better way? Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-547090 Share on other sites More sharing options...
gamefreak13 Posted May 22, 2008 Author Share Posted May 22, 2008 Got it.. but if there is a better or regexish way of doing it, I'm all ears. $sometext = strtolower("thelinkgoeshere"); preg_match('/friendid=([^&]*)/',$sometext,$out); Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-547091 Share on other sites More sharing options...
sasa Posted May 22, 2008 Share Posted May 22, 2008 preg_match('/friendid=([^&]*)/i',$sometext,$out); or <?php $sometext = "site.com/viewprofile.cfm?blah=yay&friendID=12828&mytoken=dsf22d23d"; $sometext=parse_url($sometext); parse_str($sometext['query'],$out); $out=array_change_key_case($out); $friendid = $out['friendid']; echo $friendid; ?> Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-547095 Share on other sites More sharing options...
gamefreak13 Posted May 22, 2008 Author Share Posted May 22, 2008 I used the first one. The second one looks excessive (unless there is some sort of benefit?). Beautiful. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-547100 Share on other sites More sharing options...
gamefreak13 Posted May 22, 2008 Author Share Posted May 22, 2008 I got another one.. If I have something like myspace.com/bluemonkey00 or myspace.com/23481932 .. how do I get just the username or userid? In case anyone is wondeirng, I'm making a myspace logger. It utilizes the referer to see what they saw. I personally can look at the url and figure it out, but it looks better to say "Viewed profile bluemonkey00" then the ugly url. This one is a little more tricky because something like myspace.com/contactus (if thats even real?) would come up too. So I'm not sure if this is even possible. I appreciate the help so far, so if this is a little too much its cool. Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-547101 Share on other sites More sharing options...
gamefreak13 Posted May 22, 2008 Author Share Posted May 22, 2008 Ok this one really has me confused as to why its not working. See, the referer urls may be for bulletins (which contain messageid) or profile views (which contain friendid). So I tried this but it makes them all come out as "Viewed Bulletin " without any numbers... even for the ones that dont contain messageid. I was the links containing messageid to output one thing, and the ones containing friendid to output something else. If "friendid" exists in the referer, then $refererclean equals xyz. If "messageid" exists in the referer, then $refererclean equals abc. This works: preg_match('/friendid=([^&]*)/i',$result['referer'],$output); $refererclean = "Viewed profile #".$output[1]; This doesn't: if(preg_match('/friendid=([^&]*)/i',$result['referer'],$output)); { $refererclean = "Viewed profile #".$output[1]; } if(preg_match('/messageid=([^&]*)/i',$result['referer'],$output)); { $refererclean = "Viewed bulletin #".$output[1]; } Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-547106 Share on other sites More sharing options...
sasa Posted May 22, 2008 Share Posted May 22, 2008 <?php $sometext = "myspace.com/bluemonkey00"; $sometext= pathinfo($sometext); print_r($sometext); ?> Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-547114 Share on other sites More sharing options...
gamefreak13 Posted May 22, 2008 Author Share Posted May 22, 2008 Thanks.. simple code there sasa. I'll get that in later. Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-547117 Share on other sites More sharing options...
gamefreak13 Posted May 27, 2008 Author Share Posted May 27, 2008 This doesn't work perfectly. Granted, the usernames should only contain letters and numbers and underscores and hypens, but something like myspace.com/contactus (example) would return contactus when thats not a myspace profile. Maybe I could do a list of banned results? <?php $sometext = "myspace.com/bluemonkey00&var=something&test=ok"; $sometext= pathinfo($sometext); print_r($sometext['filename']); ?> Outputs bluemonkey00&var=something&test=ok Quote Link to comment https://forums.phpfreaks.com/topic/106721-uhh/#findComment-550814 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.