|
Posted by Rami Elomaa on 05/04/07 18:44
Patrick kirjoitti:
> Hello All,
>
> Been beating my head on the wall trying to get this working. Especially
> because of my *tweener level of php and regex experience.
>
> I have this $filename = C17AA001.000
>
> I want to split it like this $a = C17AA $b = 001 $c = .000
>
> I have tried this but can't get it to work.
>
> list($a, $b, $c,) = split("^[0-9a-zA-Z]{5}[0-9]{3}\.[0-9]{3}",$filename);
>
> echo $a;
> echo $b;
> echo $c;
>
> What am I missing here? Two days of googling and php.net have not
> cleared me up.
The reg ex argument you give to split is not the entire string pattern,
just the delimiter. You tell what pattern splits the string into pieces.
Now you're giving it the entire string pattern that does match the
whole string but so it basicly splits the string into two, the empty
before the string and the empty after the string.
You should be using preg_match 'stead of split. Try something like this:
preg_match("^[0-9a-zA-Z]{5}[0-9]{3}\.[0-9]{3}",$matches,$filename);
list($a, $b, $c,) = $matches;
HTH
--
Rami.Elomaa@gmail.com
"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
[Back to original message]
|