Last active
July 6, 2019 00:34
-
-
Save tomhazledine/2964e71499c4fd28e469997933982d52 to your computer and use it in GitHub Desktop.
Convert Numbers Into Words
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* DISPLAY NUMBERS | |
* | |
* Convert raw numbers into human-readable words. | |
* | |
* Borrowed (and very much simplified) from: | |
* http://www.karlrixon.co.uk/writing/convert-numbers-to-words-with-php/ | |
* @param integer $number Raw number. | |
* @return string Number as a word. | |
*/ | |
function convert_number_to_words($number) { | |
$dictionary = 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 => 'fourty', | |
50 => 'fifty', | |
60 => 'sixty', | |
70 => 'seventy', | |
80 => 'eighty', | |
90 => 'ninety', | |
100 => 'hundred' | |
); | |
$string = $dictionary[$number]; | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment