Use preg_match to capture them in your functions.
Regex for capturing the letters:
/([A-Z]+)/i
Regex for capturing the numbers:
/([0-9]+)/
So you could have functions like:
function getAlpha($source) {
preg_match("/([A-Z]+)/i", $source, $matches);
return $matches[1];
}
function getNumeric($source) {
preg_match("/([0-9]+)/", $source, $matches);
return $matches[1];
}
And you would use it like this:
echo getAlpha("butterfly12"); //butterfly
echo getNumeric("butterfly12"); //12
EDIT
I now think I understand what you mean, perhaps these functions would work best for you:
function getAlpha($source) { //Gets whatever text is before a number.
$alpha = "";
if(preg_match("/^([A-Z]+)\d+/i", $source, $matches)) {
$alpha = $matches[1];
}
return $alpha;
}
function getNumeric($source) { //Gets whatever number is after the text.
$numeric = "";
if(preg_match("/(\d+)$/", $source, $matches)) {
$numeric = $matches[1];
}
return $numeric;
}
5
solved How performing these two function?