## Spoken Numbers by Endres

```<?php\x0d
\x0d
// Found on google! Will be optimized!\x0d
\x0d
\$ones = array(\x0d
"",\x0d
" one",\x0d
" two",\x0d
" three",\x0d
" four",\x0d
" five",\x0d
" six",\x0d
" seven",\x0d
" eight",\x0d
" nine",\x0d
" ten",\x0d
" eleven",\x0d
" twelve",\x0d
" thirteen",\x0d
" fourteen",\x0d
" fifteen",\x0d
" sixteen",\x0d
" seventeen",\x0d
" eighteen",\x0d
" nineteen"\x0d
);\x0d
\x0d
\$tens = array(\x0d
"",\x0d
"",\x0d
" twenty",\x0d
" thirty",\x0d
" forty",\x0d
" fifty",\x0d
" sixty",\x0d
" seventy",\x0d
" eighty",\x0d
" ninety"\x0d
);\x0d
\x0d
\$triplets = array(\x0d
"",\x0d
" thousand",\x0d
" million",\x0d
" billion",\x0d
" trillion",\x0d
" quintillion",\x0d
" sextillion",\x0d
" septillion",\x0d
" octillion",\x0d
" nonillion"\x0d
);\x0d
\x0d
// recursive fn, converts three digits per pass\x0d
function convertTri(\$num, \$tri) {\x0d
global \$ones, \$tens, \$triplets;\x0d
\x0d
// chunk the number, ...rxyy\x0d
\$r = (int) (\$num / 1000);\x0d
\$x = (\$num / 100) % 10;\x0d
\$y = \$num % 100;\x0d
\x0d
// init the output string\x0d
\$str = "";\x0d
\x0d
// do hundreds\x0d
if (\$x > 0)\x0d
\$str = \$ones[\$x] . " hundred";\x0d
\x0d
// do ones and tens\x0d
if (\$y < 20)\x0d
\$str .= \$ones[\$y];\x0d
else\x0d
\$str .= \$tens[(int) (\$y / 10)] . \$ones[\$y % 10];\x0d
\x0d
// add triplet modifier only if there\x0d
// is some output to be modified...\x0d
if (\$str != "")\x0d
\$str .= \$triplets[\$tri];\x0d
\x0d
// continue recursing?\x0d
if (\$r > 0)\x0d
return convertTri(\$r, \$tri+1).\$str;\x0d
else\x0d
return \$str;\x0d
}\x0d
\x0d
// returns the number as an anglicized string\x0d
function convertNum(\$num) {\x0d
\$num = (int) \$num;    // make sure it's an integer\x0d
\x0d
if (\$num < 0)\x0d
return "negative".convertTri(-\$num, 0);\x0d
\x0d
if (\$num == 0)\x0d
return "zero";\x0d
\x0d
return convertTri(\$num, 0);\x0d
}\x0d
\x0d
while(\$l=intval(fgets(STDIN))) {\x0d
echo ltrim(convertNum(\$l))."\n";\x0d
}\x0d
?>```

Note that non-ascii characters in the above source code will be escaped (such as \x9f).