View Full Version : Separate one string in two

02-26-2008, 02:33 PM
Hi all,

Sure it is a piece of cake, but in my numbness I don't see how to do it ..
I have the following string “color124.gif” and I want to separate it in two different strings “color” and “124” (124 can be a int) .. How can I do it?

Thanks a lot in advance!

02-26-2008, 02:49 PM

$string = "color124.gif";

$pattern = array("/[a-z]+/", "/[1-9]+/");
$parts = array();

foreach ($pattern as $val) {
preg_match ($pattern[$i], $string, $match);
$parts[$i] = $match[0];
print "Part 1: ".$parts[0];
print "Part 2: ".$parts[1];


02-26-2008, 03:54 PM
gorgeous, thank u very much!