Click to See Complete Forum and Search --> : Cutting strings! - Help!


deep
08-11-2003, 06:45 PM
Hi,

I got this string that looks exactelly like this with 2 spaces:

"hello 532 there"

Now, the problem Im having is that I need to cut out the 532 from the string and place this text into a variable. The number 532 can be ANY number (example: 1, 23, 234289)! So we have to count the characters somehow untill we find the second space and extract the exact number... how do I do this?

I would appreciate an example very much!!

Thanks!!

Jona
08-11-2003, 08:21 PM
Will there be an exact number of spaces or characters every time, or will it just have a number in a string somewhere, placed randomly?

[J]ona

pyro
08-11-2003, 10:39 PM
Just use a regular expression to split at every blank space:

<?PHP
$str = "hello 532 there";
$str = preg_split("/\\s/",$str); #split at each blank space
$num = $str[1];
echo $num;
?>

deep
08-13-2003, 05:35 AM
Thanks!

pyro
08-13-2003, 06:55 AM
You're welcome... :)