In PHP, is there an easy way to convert a number to a word? For instance, 27 to twenty-seven.
+1
A:
There's no built-in way that I'm aware of, but if you have a look at my example code for this question (in C#) it should be easy enough for you to get working. Basically it'd just be a matter of untyping the variables and adding the $
prefix where appropriate and it should work.
Matthew Scharley
2008-11-10 10:43:52
+3
A:
http://bloople.net/num2text/ includes source code.
"It's copyright, but you can use it freely and modify it however you want."
mrhahn
2008-11-10 10:46:03
+1
A:
Alternatively, you can use the NumberFormatter class from 'intls' package in PHP . Here's a sample code to get you started (for commandline):
<?php
if ($argc < 3)
{
echo "usage: php {$argv[0]} lang-tag number ...\n";
exit;
}
array_shift($argv);
$lang_tag = array_shift($argv);
$nf1 = new NumberFormatter($lang_tag, NumberFormatter::DECIMAL);
$nf2 = new NumberFormatter($lang_tag, NumberFormatter::SPELLOUT);
foreach ($argv as $num)
{
echo $nf1->format($num).' is '.$nf2->format($num)."\n";
}
?>