Page 1 of 1

Converting integer to string

Posted: Thu Apr 17, 2003 2:36 pm
by AlphaQuam
I need to convert integers to their equivalent word, for example...

Code: Select all

7 > "seven"
21 > "twenty-one"
84 > "eighty-four"
Is there any function in PHP which handles this? If not, is there an easy way to implement it?

Thanks!
Jon

Posted: Thu Apr 17, 2003 2:54 pm
by Rob the R
There does not appear to be a PHP function for this 8O, but someone has posted the code for a custom function:
http://www.php.net/manual/en/function.n ... .php#26234

I have not tested this myself.

Posted: Thu Apr 17, 2003 6:08 pm
by McGruff
I wonder if you could use the php date functions: ie mktime() a number into a pseudo-timestamp then use the date() function? Away from home right now so don't have the manual to refer to. I guess that would only get you up to 31 anyway.

Posted: Thu Apr 17, 2003 8:57 pm
by AlphaQuam
damn rob... that's perfect... thanks so much. i'll test it right now! :)

Posted: Thu Apr 17, 2003 10:11 pm
by AlphaQuam
it works very nicely... only problem is i had to change the code to output "twenty-one" instead of "twenty one" but other than that... perfect.

thanks again :)