louisl;10935358 wrote:Both those functions had flaws for the data I was using as examples, but it they led me down the right path so thanks.
No, mine works perfectly with the example data.
Data from the regexp:
AB
A
CB
X
CC
ZB
Y
And from your example
AB
A
CB
X
CC
ZB
Y
As for scupolous code, there were just two small issues that are easy to fix, and I still find his code more readable than yours. It is also more efficient. The two things missing is start condition and the other was if the whole string is ok.
function getBeforeFirstNumber($string)
{
if (is_numeric($string[0])) // added
return false; // added
for($i=0;$i<strlen($string);$i++)
{
if(is_numeric($string[$i]))
{
return substr($string,0,$i);
}
}
return $string; // added
}