PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Sat Jul 08, 2006 8:50 am
I have a string:
Code: Select all
1_vbJG4fWHr5oQrVZmoIRdUZ58K6MNRC9ieJOBpGjBexsvONd6wvNow all i'm wanting to do is use whatever is before the '_' (underscore) as this number is a user ID number and i'm trying to get it from it and have it as a cookie but I can't seem to extract just that. I can get everything after the underscore but not before.
Code: Select all
<?php
$thecook = "1_vbJG4fWHr5oQrVZmoIRdUZ58K6MNRC9ieJOBpGjBexsvONd6wv";
$thecook2 = strstr($thecook, '_');
echo $thecook2;
?>^That's what i'm using at the moment to get everything after the '_' but I want before it.
Any ideas?
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Sat Jul 08, 2006 8:53 am
just do this:
Code: Select all
$thecook = "1_vbJG4fWHr5oQrVZmoIRdUZ58K6MNRC9ieJOBpGjBexsvONd6wv";
$thecook2 = array();
$thecook2 = explode("_", $thecook);
echo $thecook2[0];
Dale
Forum Contributor
Posts: 466 Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks
Post
by Dale » Sat Jul 08, 2006 9:13 am
Cheers
dull1554 .
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Sat Jul 08, 2006 9:17 am
not really the reverse of strstr, but its a means to an end
no problem
Ollie Saunders
DevNet Master
Posts: 3179 Joined: Tue May 24, 2005 6:01 pm
Location: UK
Post
by Ollie Saunders » Sat Jul 08, 2006 3:42 pm
not really the reverse of strstr, but its a means to an end Very Happy
but what is the opposite of strstr? :S
Kinda like asking what's after space. Although i'm sure there's some wise ass who says that its milk.
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Sat Jul 08, 2006 5:27 pm
1. if i had my php manual at my side i'd find some function that is the exact opposite of strstr... likt intint
2. you know you can't deny the fact that all that is, was and will be came from the outer milkyness of the thing u call a universe