All pastes #564501 Raw Edit

Stuff

public php v1 · immutable
·published 2007-06-13 16:55 UTC
rendered paste body
#!/usr/bin/php<?php$digits = array('', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');$teens = array('ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen');$tens = array('', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety');$total = 0;for ($i = 1; $i < 1000; $i++) {        $string = '';        $chars = str_split(strrev($i));        if (isset($chars[1]) && $chars[1] == 1) {                $total += strlen($teens[$chars[0]]);                $string = $teens[$chars[0]] . " ";        }        else {                $total += strlen($digits[$chars[0]]);                $string = $digits[$chars[0]] . " ";        }        if (isset($chars[1]) && $chars[1] > 1) {                $total += strlen($tens[$chars[1]]);                $string = $tens[$chars[1]] . " " . $string;        }        if (isset($chars[2])) {                $total += strlen($digits[$chars[0]]);                $string = $digits[$chars[2]] . " hundred " . $string;                if ($chars[0] == 0 && $chars[1] == 0) {                        $total += 7;                }                else {                        $total += 10;                        $string = str_replace("hundred", "hundred and", $string);                }        }        print($string . "\n");}print("one thousand\n");$total += 11;print($total);?>