Submitted by ramez.hanna on Sun, 13/06/2004 - 06:44.
( categories: Programming )

i want to parse the string "_0_ _1_ _2_ _3_" to get the numbers in an array

i could do that for a fixed string but if the string is a variable in length i can't figure out how to do it i can write preg_match(|_0_\s_(0-9?+)_\s_(0-9?+)_\s_(0-9?+)_|) but this won't repeat it self i.e it can't do the job if the string becomes "_0_ _1_ _2_ _3_ _4_ _5_" i need help


Alaa's picture
Submitted by Alaa on Sun, 13/06/2004 - 10:15.

one easy way is to use explode() to do this (it works if the seperator is a fixed string not a regexp.

$array = explode("__", "0__1__2__3__4");

if you need to split over a regexp use preg_split()

cheers,
Alaa


http://www.manalaa.net


ramez.hanna's picture
Submitted by ramez.hanna on Sun, 13/06/2004 - 10:45.

thanks for the tip i did //explode(' ', str_replace("_", "", $usersstring->chusers)) and it worked just fine


the best things in life are free --- so as myself


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.