I’m trying to take this to this string
**string** = 55 Banana Slush 25 Test into Fifty five Banana Slush twenty five test
Now I have the function to convert any numbers to words which is replaceNumtoWord($number)
However I need to take the string, find each number, then use the function on each number within the string rather then extract the numbers from it.
Any ideas or suggestions?
You can use
preg_replace_callback():If you have to use an old PHP version not supporting anonymous functions:
sidenote: the pattern
\d+will match any sequence of digits, regardless where they would appear, e.g. it will match 10, 20 and 30 in “my10, 20, 30foo”. You can change the pattern to\b\d+\bif you want to match only 20.