You can use lookarounds to match these positions:
preg_replace('/(?<=[a-z])(?=\d)|(?<=\d)(?=[a-z])/i', ' ', $str);
Depending on how you define the "letter", you can customize [a-z].
To make it work with strings, for example:
0a1b2c3
Where the solutions are without glitches.
source
share