array('hundred','thousand','million','billion','trillion','zillion'), 1 => array('one','first','ten','','th'), 2 => array('two','second','twen',0,0), 3 => array('three','third','thir',0,0), 4 => array('four','fourth','for',0,0), 5 => array('five','fifth','fif',0,0), 6 => array('six','sixth',0,0,0), 7 => array('seven','seventh',0,0,0), 8 => array('eight','eighth','eigh',0,0), 9 => array('nine','ninth',0,0,0), 10 => array('ten'), 11 => array('eleven'), 12 => array('twelve','twelfth'), 13 => array('thirteen'), 14 => array('fourteen'), 15 => array('fifteen'), 16 => array('sixteen'), 17 => array('seventeen'), 18 => array('eighteen'), 19 => array('nineteen')); $numlength = strlen($number); $mod = $numlength % 3; $trip = ceil($numlength / 3); for ($i = 0; $i < $trip; $i++) { if ($i == 0 and $mod != 0) { $begin = 0; $end = $mod; $subst = substr($number,($begin),($mod)); } elseif ($i == 0) { $begin = $mod + (($i-1) * 3); $end = $mod - 1 + ($i * 3); $subst = substr($number,(0),(3)); } else { $begin = $mod + (($i-1) * 3); $end = $mod - 1 + ($i * 3); $subst = substr($number,($begin),(3)); } if ($subst != 0) { if (strlen($subst) > 2) { $hdec = substr($subst,0,1); $ddec = substr($subst,1,2); $odec = substr($subst,2,1); } elseif (strlen($subst) > 1) { $hdec = 0; $ddec = substr($subst,0,2); $odec = substr($subst,1,1); } else { $hdec = 0; $ddec = 0; $odec = substr($subst,0,1); }; if ($hdec != 0) { $result = " " . $wnums[$hdec][0] . "-hundred "; }; if ($ddec < 20 and 9 < $ddec) { $result .= " " . $wnums[$ddec][0]; } else { if ((0 < $hdec or 1 < $trip) and ($i + 1 == $trip) and (0 < $ddec and $ddec < 10)) { $result .= "and "; }; if (19 < $ddec) { if (! $wnums[$ddec{0}][2]) { $secw = 0; } else { $secw = 2; }; if (0 < $odec) { $secx = "-"; } else { $secx = " "; }; $result .= $wnums[$ddec{0}][$secw] . "ty" . $secx; }; if (0 < $odec) { $result .= $wnums[$odec][0]; }; }; if ($i + 1 < $trip) { $result .= " " . $wnums[0][$trip - $i - 1] . ""; }; }; $newresult .= $result . " "; }; echo "

number: $number

"; echo "

cardinal number: $newresult

"; ?>