Page 1 of 1
PHP function to spell out numbers 1-9 for proper English?
Posted: Sun Nov 09, 2008 5:43 pm
by JAB Creations
In proper English the numbers zero through nine must be spelled out while ten and above do not. Is there a native function for this in PHP?
In example...
Zero
One
Two
Three
Four
Five
Six
Seven
Eight
Nine
10
11
12
etc...
Re: PHP function to spell out numbers 1-9 for proper English?
Posted: Sun Nov 09, 2008 5:52 pm
by requinix
JAB Creations wrote:In proper English the numbers zero through nine must be spelled out while ten and above do not.
Debatable.
JAB Creations wrote:Is there a native function for this in PHP?
Not that I know of.
Code: Select all
function spell($number) {
if ($number >= 0 && $number < 10 && (is_int($number) || ctype_digit($number))) {
$numbers = array("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine");
return $numbers[$number];
} else return $number;
}
Re: PHP function to spell out numbers 1-9 for proper English?
Posted: Sun Nov 09, 2008 6:10 pm
by JAB Creations
I'm not interested in debating English grammar.
That was a quick reply, did you write that function out that quickly or was it something you've had archived? I appreciate it, thanks!

Re: PHP function to spell out numbers 1-9 for proper English?
Posted: Sun Nov 09, 2008 6:35 pm
by requinix
JAB Creations wrote:That was a quick reply, did you write that function out that quickly or was it something you've had archived?
Just wrote it. Simple enough, only took a minute.