Converting integer to string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AlphaQuam
Forum Newbie
Posts: 7
Joined: Fri Feb 28, 2003 1:30 am

Converting integer to string

Post 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
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post 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.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
AlphaQuam
Forum Newbie
Posts: 7
Joined: Fri Feb 28, 2003 1:30 am

Post by AlphaQuam »

damn rob... that's perfect... thanks so much. i'll test it right now! :)
AlphaQuam
Forum Newbie
Posts: 7
Joined: Fri Feb 28, 2003 1:30 am

Post 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 :)
Post Reply