Page 1 of 1

Reverse of strstr() ?

Posted: Sat Jul 08, 2006 8:50 am
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?

Posted: Sat Jul 08, 2006 8:53 am
by dull1554
just do this:

Code: Select all

$thecook = "1_vbJG4fWHr5oQrVZmoIRdUZ58K6MNRC9ieJOBpGjBexsvONd6wv";
$thecook2 = array();
$thecook2 = explode("_", $thecook);
echo $thecook2[0];

Posted: Sat Jul 08, 2006 9:13 am
by Dale
Cheers dull1554. :)

Posted: Sat Jul 08, 2006 9:17 am
by dull1554
not really the reverse of strstr, but its a means to an end :D

no problem

Posted: Sat Jul 08, 2006 3:42 pm
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.

Posted: Sat Jul 08, 2006 5:27 pm
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