When the number is above 99 you can generate the spellout for the last two digits only. You then know where to insert the "and". In code:
$number = 125;
$numberFormatter = new \NumberFormatter('en', \NumberFormatter::SPELLOUT);
$fullSpellout = str_replace('-', ' ', $numberFormatter->format($number));
if ($number > 100) {
$lastTwoSpellout = str_replace('-', ' ', $numberFormatter->format(substr($number, -2)));
$hunderdsLength = strlen($fullSpellout) - strlen($lastTwoSpellout);
$fullSpellout = substr($fullSpellout, 0, $hunderdsLength) . 'and ' . $lastTwoSpellout;
}
echo $fullSpellout;
This outputs:
one hundred and twenty five
This is certainly not the only possible solution. There are many ways to insert the "and", and if the last two digits always generate two words you could also use that to detect where to insert the "and".
Here's a version based on words and using an array to insert the 'and':
$number = 125;
$numberFormatter = new \NumberFormatter('en', \NumberFormatter::SPELLOUT);
$spellout = str_replace('-', ' ', $numberFormatter->format($number));
if ($number > 100) {
$words = explode(' ', $spellout);
array_splice($words, -2, 0, ['and']);
$spellout = implode(' ', $words);
}
echo $spellout;