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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php