Code: Select all
<?php
/*************************************************************************************
** Copyright 2007 Neel Basu <neel.basu.z@gmail.com> Some rights Reserved **
--------------------------------------------------------------------------------------
This File Has Been Reliesed Just for Testing Purpouse It Will be Bound With the framework
After Finishing .
--------------------------------------------------------------------------------------
You can use it as long as the above message is intact
**************************************************************************************/
header("Content-Type: text/plain");
function dict($get)
{
$num[1] = "One";
$num[2] = "Two";
$num[3] = "Three";
$num[4] = "Four";
$num[5] = "Five";
$num[6] = "Six";
$num[7] = "Seven";
$num[8] = "Eight";
$num[9] = "Nine";
$num[10] = "Ten";
$num[11] = "Eleven";
$num[12] = "Twelve";
$num[13] = "Thirteen";
$num[14] = "Fourteen";
$num[15] = "Fiveteen";
$num[16] = "Sixteen";
$num[17] = "Seventeen";
$num[18] = "Eighteen";
$num[19] = "Nineteen";
$num[20] = "Twenty";
$num[30] = "Thirty";
$num[40] = "Fourty";
$num[50] = "Fivety";
$num[60] = "Sixty";
$num[70] = "Seventy";
$num[80] = "Eighty";
$num[90] = "Ninety";
//$num["t"] = "ty";
$num["hund"] = "Hundreed";
$num["thsnd"] = "Thousand";
$num["mill"] = "Million";
$num["bill"] = "Billion";
$num["trill"] = "Billion";
$num["blank"] = "";
$num[00] = "";
$num[01] = "One";
$num[02] = "Two";
$num[03] = "Three";
$num[04] = "Four";
$num[05] = "Five";
$num[06] = "Six";
$num[07] = "Seven";
$num[08] = "Eight";
$num[09] = "Nine";
$num[0] = "Zero";
return $num[$get];
}
function dict_pos($get)
{
//$num[0] = "Hundreed";
$num[0] = "Thousand";
$num[1] = "Million";
$num[2] = "Billion";
$num[3] = "Trillion";
$num[4] = "Quadrillion";
$num[5] = "Quintillion";
$num[6] = "Sextillion";
$num[7] = "Octillion";
$num[8] = "Nonillion";
$num[9] = "Decillion";
$num[10] = "Undecillion";
$num[11] = "Duodecillion";
$num[12] = "Tredecillion";
$num[13] = "Quattuordecillion";
$num[14] = "Quindecillion";
$num[15] = "Sexdecillion";
$num[16] = "Septendecillion";
$num[17] = "Octodecillion";
$num[18] = "Novemdecillion";
$num[19] = "Vigintillion";
$num[20] = "Centillion";
return $num[$get];
}
function decade($num_str)
{
$to_str = (string)($num_str);
if($to_str[1] == 0)
{
if($to_str >= 10)
{
return dict($to_str[0]*10);
}
else
{
return dict($to_str[0]);
}
}
else
{
if($num_str >= 11 && $num_str <= 19)
{
return dict($num_str);
}
else
{
return dict($to_str[0]*10)."-".dict($to_str[1]);
}
}
}
function hundreed($num_str)
{
$to_str = (string)($num_str);
if($num_str >= 0 && $num_str <= 10)
{
return dict($to_str);
}
if($num_str >= 11 && $num_str <= 99)
{
return decade($to_str);
}
if($num_str >= 100 && $num_str <= 999)
{
$dec = (int)($to_str[1].$to_str[2]);
if($dec != 0)
{
return dict($to_str[0])." ".dict("hund")." ".decade($dec);
}
else
{
return dict($to_str[0])." ".dict("hund");
}
}
}
function to_word($get_int)
{
$to_str = (string)$get_int;
$len = strlen($to_str)-1;
for($i=$len;$i>=0;$i-=3)
{
$part[2] = $to_str[$i];
$part[1] = $to_str[$i-1];
$part[0] = $to_str[$i-2];
if($part[0] != '0')
{
$hnd = $part[0].$part[1].$part[2];
}
else
{
if($part[1] != '0')
{
$hnd = $part[1].$part[2];
}
else
{
$hnd = $part[2];
}
}
$num_r[] = hundreed($hnd);
}
for($i=count($num_r)-1;$i>=0;$i--)
{
if($i != (count($num_r)-1))
{
$ret[] = dict_pos($i);
}
$ret[] = $num_r[$i];
}
foreach($ret as $key => $val)
{
$return .= $val;
if($key != (count($ret)-1))
{
$return .= " ";
}
}
for($i=0;$i<=21;$i++)
{
$return = str_replace("Zero ".dict_pos($i)." ", "", $return);
}
return $return;
}
?>
<?php
$num = "999999999999999999999999999999999999999999999999999999999999999999";
echo $num."\n".to_word($num);
?>Numbers More than Billion Should be in " " or ' ' Numbers such as 2005 doesn't needs any " or 'Browser Output wrote:999999999999999999999999999999999999999999999999999999999999999999
Nine Hundreed Ninety-Nine Centillion Nine Hundreed Ninety-Nine Vigintillion Nine Hundreed Ninety-Nine Novemdecillion Nine Hundreed Ninety-Nine Octodecillion Nine Hundreed Ninety-Nine Septendecillion Nine Hundreed Ninety-Nine Sexdecillion Nine Hundreed Ninety-Nine Quindecillion Nine Hundreed Ninety-Nine Quattuordecillion Nine Hundreed Ninety-Nine Tredecillion Nine Hundreed Ninety-Nine Duodecillion Nine Hundreed Ninety-Nine Undecillion Nine Hundreed Ninety-Nine Decillion Nine Hundreed Ninety-Nine Nonillion Nine Hundreed Ninety-Nine Octillion Nine Hundreed Ninety-Nine Sextillion Nine Hundreed Ninety-Nine Quintillion Nine Hundreed Ninety-Nine Quadrillion Nine Hundreed Ninety-Nine Trillion Nine Hundreed Ninety-Nine Billion Nine Hundreed Ninety-Nine Million Nine Hundreed Ninety-Nine Thousand Nine Hundreed Ninety-Nine