As noted above, I don't know PHP.
If this were FoxPro, I would do it this way:
zvar = ' abC 2 1 def '
zspace = ' '
znull = ''
zvar = UPPER(CHRTRAN(zvar, zspace, znull)) && Remove all spaces, Change to upper case
z = zvar
DO WHILE NOT EMPTY(z)
zlen = LEN(z)
IF ISDIGIT(RIGHT(z, 1))
z = znull && Digit found, Exit
ELSE
z = LEFT(z, zlen - 1) && Digit not found, Loop
ENDIF
ENDDO
zvar = ALLTRIM(STUFF(zvar, zlen + 1, 0, zspace)) && Insert space, Trim any trailing space
The only time this fails is if the string variable contains no numeric digits. This also assumes that the string is entered correctly, Alpha + Numeric + Maybe more alpha.
Based on what I see in John's code above, a similar solution should be available using PHP.
Not tested.