I have string:
$string = \'Five People\';
I want to replace all number-words into numbers. So results are:
$strin
You can use this regex:
\b(zero|a|one|tw(elve|enty|o)|th(irt(een|y)|ree)|fi(ft(een|y)|ve)|(four|six|seven|nine)(teen|ty)?|eight(een|y)?|ten|eleven|forty|hundred|thousand|(m|b)illion|and)+\b
By the way, there might be a better regex out there. Until someone posts it, you can use the following implementation
$regex = '/\b(zero|a|one|tw(elve|enty|o)|th(irt(een|y)|ree)|fi(ft(een|y)|ve)|(four|six|seven|nine)(teen|ty)?|eight(een|y)?|ten|eleven|forty|hundred|thousand|(m|b)illion|and)+\b/i';
function word_numbers_to_numbers($string) {
return preg_replace_callback($regex, function($m) {
return words_to_number($m[0]);
},$string);
}