function number_string ($number
{
$names = array
0=>"zero", 1=>"one", 2=>"two", 3=>"three", 4=>"four"
5=>"five", 6=>"six", 7=>"seven", 8=>"eight", 9=>"nine"
10=>"ten", 11=>"eleven", 12=>"twelve", 13=>"thirteen", 14=>"fourteen"
15=>"fifteen", 16=>"sixteen", 17=>"seventeen", 18=>"eighteen", 19=>"nineteen"
20=>"twenty", 30=>"thirty", 40=>"forty", 50=>"fifty"
60=>"sixty", 70=>"seventy", 80=>"eighty", 90=>"ninety"
);
$triplets = array
100=>"hundred"
1000=>"thousand"
1000000=>"million"
1000000000=>"billion"
1000000000000=>"trillion"
1000000000000000=>"quadrillion"
1000000000000000000=>"quintillion"
1000000000000000000000=>"sextillion"
1000000000000000000000000=>"septillion"
1000000000000000000000000000=>"octillion"
1000000000000000000000000000000=>"nonillion"
);
krsort$names);
krsort$triplets);
if (abs$number) > PHP_INT_MAX)
throw new Exception'Maximum integer size for this version of PHP is '.PHP_INT_MAX);
$prefix = ''
$str = ''
if ($number<0) {
$prefix = 'negative '
$number = $number*-1;
}
$remainder = 0;
if ($number>=100) {
foreach ($triplets as $num=>$name) {
if ($num<=$number) {
$str = $name
$remainder = $number % $num
$number = floor$number$num);
break
}
}
// how many of the triplets?
$str = number_string$number).' '$str
if ($remainder<100) $separator = ' and '
else $separator = ', '
} else {
foreach ($names as $num=>$name) {
if ($num<=$number) {
$str = $name
$remainder = $number % $num
break
}
}
$separator = '-'
}
// remainder to tack on?
if ($remainder>0) {
$str = $str$separatornumber_string$remainder);
}
return $prefix$str
}