Convert Number | integer with words

I would like to convert an integer into words, for example: 29 will become TWENTY-NINE and 50 will be FIVE. How can I achieve this using PHP?

Here is what I have, but it does not give the desired result.

$fees_so = $form_data_fees['field']['4'];
$feesInWords = strval($fees_so);
echo $feesInWords;
+4
source share
3 answers

You can use the NumberFormatter class with SPELLOUT:

$nf = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $nf->format(1999); // one thousand nine hundred ninety-nine
+6
source

Assuming you have an array:

$list_of_fees = array("£29", "£50", "£64");;
for($i = 0; $i < 3; $i++)
    echo substr($list_of_fees[$i], 1) . " Pounds";
+1
source

I ended up finding a solution using code from @ aniket-sahrawat with a little tweaking

Here is the code if someone needs it in the future ...

<?php
$fees_so = $form_data_fees['field']['4'];
$words = filter_var($fees_so, FILTER_SANITIZE_NUMBER_INT);
$nf = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $nf->format($words);
?>
+1
source

Source: https://habr.com/ru/post/1694684/


All Articles