...

View Full Version : Separate one string in two



Lleoun
02-26-2008, 01: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!

matak
02-26-2008, 01:49 PM
<?php

$string = "color124.gif";

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

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

?>

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum