retrieve strings from variable in php
Posted on 2012-03-16
I have a variable $var1 and it will always contain a string like "UK1234" or say "EWP123456". I basically need to get into $var2 the text prefix and into $var3, the rest of the numeric string. Problem is that the text prefix may be 2 characters or it may be 3 characters, so I can't use something like,
$var2 = substr($var1,0,2);
If it helps, the text prefix in he string can only be one of the following.....
So, some data examples of what I need are as follows.
$var1 = "EWP123456"
$var2 = "EWP"
$var3 = "123456"
$var1 = "UK1234"
$var2 = "UK"
$var3 = "1234"