Reverse of strstr() ?

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

Post Reply
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Reverse of strstr() ?

Post by Dale »

I have a string:

Code: Select all

1_vbJG4fWHr5oQrVZmoIRdUZ58K6MNRC9ieJOBpGjBexsvONd6wv
Now 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?
User avatar
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 »

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 »

Cheers dull1554. :)
User avatar
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 »

not really the reverse of strstr, but its a means to an end :D

no problem
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

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.
User avatar
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 »

1. if i had my php manual at my side i'd find some function that is the exact opposite of strstr... likt intint :-P :D

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
Post Reply