<?
include_once('opendb.php');
$x=$_REQUEST['x'];
$n=$_REQUEST['n'];
$followup=$_REQUEST['followup'];
//***************** number to words
function word($x)
{
$x=str_replace(".","-",$x);
$num=explode('-',$x); 

if($num[1]>0)
{
 $m="Rupees ".ConvertToWords($num[0])." and ".ConvertToWords($num[1])." paise";
 return $m;
}
else
{ $m= "Rupees ".ConvertToWords($num[0]);
 return $m;
}

}
 function ConvertToWords($n, $followup='')  
 {  
     if($n==0)  
     {  
         if($followup=='no')  
         {  
             return "";  
             exit();  
         }  
        else  
         {  
             return "zero";  
             exit();  
         }  
     }  
     switch($n)  
    {  
         case 1: return "one"; break;  
         case 2: return "two"; break;  
         case 3: return "three"; break;  
         case 4: return "four"; break;  
         case 5: return "five"; break;  
         case 6: return "six"; break;  
         case 7: return "seven"; break;  
         case 8: return "eight"; break;  
         case 9: return "nine"; break;  
         case 10: return "ten"; break;  
         case 11: return "eleven"; break;  
         case 12: return "twelve"; break;  
         case 13: return "thirteen"; break;  
         case 14: return "fourteen"; break;  
         case 15: return "fifteen"; break;  
         case 16: return "sixteen"; break;  
         case 17: return "seventeen"; break;  
         case 18: return "eighteen"; break;  
         case 19: return "nineteen"; break;  
        case 20: return "twenty"; break;  
         case 30: return "thirty"; break;  
         case 40: return "forty"; break;  
         case 50: return "fifty"; break;  
         case 60: return "sixty"; break;  
         case 70: return "seventy"; break;  
         case 80: return "eighty"; break;  
         case 90: return "ninety"; break;  
         case 100: return "one hundred"; break;  
         case 1000: return "one thousand"; break;  
         case 100000: return "one lakh"; break;  
         default:  
         {  
             if($n<100)  
             {  
                 return ConvertToWords(floor($n/10)*10, 'no')."-".ConvertToWords($n%10, 'no'); break;  
             }  
             elseif($n<1000)  
             {  
                 return ConvertToWords(floor($n/100), 'no')." hundred ".ConvertToWords($n%100, 'no'); break;  
             }  
             elseif($n<100000)  
             {  
                 return ConvertToWords(floor($n/1000), 'no')." thousand ".ConvertToWords($n%1000, 'no'); break;  
             }  
             elseif($n<10000000)  
             {  
                 return ConvertToWords(floor($n/100000), 'no')." lakh ".ConvertToWords($n%100000, 'no'); break;  
             }  
             else  
             {  
                 return "Something else"; break;  
             }  
         }  
     }  
 }  

/*****************************************************************************/

function nozero($x)
{
 if($x==0)
   return ' ';
 else
   return $x;
}

?>
