Re: int to string

From: Date: Thu, 06 Apr 2006 16:21:37 +0000
Subject: Re: int to string
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-233381@lists.php.net to get a copy of this message
At 4:27 PM -0700 4/5/06, Tanner Postert wrote:
I don't think it's built in, so I was wondering ya'll would recommend as the best way to convert int to string, not basic type casting, but converting to the english word the int represents. Something like this: 5 = "Five" or 20 = "Twenty"
Tanner: The following demo will work "as-is", but needs to be expanded and optimized. But, this should give you the basic framework. <?php $num = 123; $a = round($num/100); $num = $num - ($a*100); $text = numtext($a) . " hundred, "; $a = round($num/10); $num = $num - ($a*10); $text .= numtext($a) . " tens, and "; $a = round($num/1); $num = $num - ($a*1); $text .= numtext($a); echo($text); ?> <?php function numtext($a) { $b=""; switch ($a) { case 1; $b = "one"; break; case 2; $b = "two"; break; case 3; $b = "three"; break; } return ($b); } ?> tedd -- -------------------------------------------------------------------------------- http://sperling.com

« previous php.general (#233381) next »