Jump to content

Uhh....


gamefreak13

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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! :)

Link to comment
Share on other sites

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.".

Link to comment
Share on other sites

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;
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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;
?>

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

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];
	}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.