/ Published in: PHP
this could be expanded to the billions place, but c'mon really people? it's got to call it quits somewhere
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", 30 => "thirty", 40 => "forty", 50 => "fifty", 60 => "sixty", 70 => "seventy", 80 => "eighty", 90 => "ninety" ); function int_to_words($x) { global $nwords; { $w = '#'; { $w = '#'; }else{ if($x < 0) { $w = 'minus '; $x = -$x; }else{ $w = ''; } if($x < 21) { $w .= $nwords[$x]; }else if($x < 100) { if($r > 0) { $w .= '-'. $nwords[$r]; } } else if($x < 1000) { if($r > 0) { $w .= ' and '. int_to_words($r); } } else if($x < 1000000) { if($r > 0) { $w .= ' '; if($r < 100) { $w .= 'and'; } $w .= int_to_words($r); } } else { if($r > 0) { $w .= ' '; if($r < 100) { $word .= 'and '; } $w .= int_to_words($r); } } } return $w; } $word = int_to_words($_POST['num']); echo $word.'<br /><a href="'.$_SERVER['PHP_SELF'].'"> try again</a><br />'; }else{ echo ' <form method="post" action="'.$_SERVER['PHP_SELF'].'"> <input type="text" name="num"> <input type="submit" value="Convert"> </form>'; } ?>