<?php
/**
* tkconvert.php :: Main tkconvert class and setup file
*
* tkconvert version 0.1.1
* copyright (c) 2007 by Mahfuz -ur Rahman
*
*
* tkconvert is an open source PHP class library for easily convert money in words.
*
* xajax is released under the terms of the LGPL license
* http://www.gnu.org/copyleft/lesser.html#SEC3
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* FOR ANY SAGGETION PLESE CONTACT hide@address.com
*
*/
/*
----------------------------------------------------------------------------
| example of this class is given in tkconvert_example.php:
| for bangla font go to http://www.ekushey.org/?page/rupali_layout
----------------------------------------------------------------------------
*/
class tkconvert
{
var $words = array();
var $places = array();
var $amounta = array();
var $amount_in_words;
var $amount;
var $num;
var $numlength;
var $decimal;
var $decimal_len;
function tkconvert($am)
{
$this->amount = $am;
}
function setamount($m)
{
$this->amount = $m;
}
function convert($lan)
{
$this->assign($lan); //use language
$temp = $this->amount;
$temp = (string)$this->amount;
$pos = strpos($temp,".");
$str = explode('.',$temp);
$this->decimal = $str[1];
$this->num = $str[0];
if ( !empty($dec) )
{
$this->decimal = $dec;
$this->decimal_len = strlen($this->decimal);
$this->decimal = substr($this->decimal,1,$this->decimal_len+1);
}
/* get last 2 digit */
$this->getlast2digit();
$l1 = strlen($this->num);
if ( $l1 != 0)
{
$this->gethundred();
}
$l1 = strlen($this->num);
if ( $l1 != 0)
{
$this->getthousand();
}
$llac = strlen($this->num);
if ( $llac != 0)
{
$this->getlac();
}
$lcrore = strlen($this->num);
if ( $lcrore != 0)
{
$this->getcrore();
}
$lcrore2 = strlen($this->num);
if ( $lcrore2 != 0)
{
$this->gethundred();
}
$lcrore3 = strlen($this->num);
if ( $lcrore3 != 0)
{
$this->getthousand();
}
}
function getlast2digit()
{
/*Last 2 Digit*/
$last2d = substr($this->num,-1,1);
$lastzero = substr($this->num,-2,1);
$last2f = substr($this->num,-2,2);
if (array_key_exists($last2f, $this->words))
{
$s = $this->words[$last2f];
}
else
{
$last2de = substr($this->num,-2,2);
$last2di = $last2de - $last2d;
$s = $this->words[$last2di]."".$this->words[$last2d];
}
$l = $s;
$t = $this->num;
$numlen = strlen($this->num)-2;
$this->num = substr($t,0,$numlen);
//$l = $this->getlast($this->num);
if ( strcmp($last2f,'00') != 0 )
{
$fullword = $l.$this->places[0];
array_push($this->amounta,$fullword);
}
}
function gethundred()
{
// for hundred
$t = substr($this->num,-1,1);
if ( strcmp($t,'0') != 0 )
{
$l = $this->words[$t];
$numlen = strlen($this->num)-1;
$this->num = substr($this->num,0,$numlen);
$fullword = $l.$this->places[1];
array_push($this->amounta,$fullword);
}
else
{
$numlen = strlen($this->num)-1;
$this->num = substr($this->num,0,$numlen);
}
}
function getthousand()
{
$last2d = substr($this->num,-1,1);
$lastzero = substr($this->num,-2,1);
$last2f = substr($this->num,-2,2);
if (array_key_exists($last2f, $this->words))
{
$s = $this->words[$last2f];
}
else
{
$last2de = substr($this->num,-2,2);
$last2di = $last2de - $last2d;
$s = $this->words[$last2di]."".$this->words[$last2d];
}
$l = $s;
$t = $this->num;
$numlen = strlen($this->num)-2;
$this->num = substr($t,0,$numlen);
if ( strcmp($last2f,'00') != 0 )
{
$fullword = $l.$this->places[2];
array_push($this->amounta,$fullword);
}
}
function getlac()
{
$last2d = substr($this->num,-1,1);
$lastzero = substr($this->num,-2,1);
$last2f = substr($this->num,-2,2);
if (array_key_exists($last2f, $this->words))
{
$s = $this->words[$last2f];
}
else
{
$last2de = substr($this->num,-2,2);
$last2di = $last2de - $last2d;
$s = $this->words[$last2di]."".$this->words[$last2d];
}
$l = $s;
$t = $this->num;
$numlen = strlen($this->num)-2;
$this->num = substr($t,0,$numlen);
if ( strcmp($last2f,'00') != 0 )
{
$fullword = $l.$this->places[3];
array_push($this->amounta,$fullword);
}
}
function getcrore()
{
$last2d = substr($this->num,-1,1);
$lastzero = substr($this->num,-2,1);
$last2f = substr($this->num,-2,2);
if (array_key_exists($last2f, $this->words))
{
$s = $this->words[$last2f];
}
else
{
$last2de = substr($this->num,-2,2);
$last2di = $last2de - $last2d;
$s = $this->words[$last2di]."".$this->words[$last2d];
}
$l = $s;
$t = $this->num;
$numlen = strlen($this->num)-2;
$this->num = substr($t,0,$numlen);
$fullword = $l.$this->places[4 ];
array_push($this->amounta,$fullword);
}
function display()
{
foreach ($this->amounta as $a)
{
$this->amount_in_words = $this->amount_in_words.array_pop($this->amounta);
//echo "<br>".$a;
}
return $this->amount_in_words;
}
function getNum()
{
return $this->amount;
}
function assign($lan = 'en') {
switch ($lan)
{
case 'en':{
$this->words["1"] = " One"; $this->words["2"] = " Two";
$this->words["3"] = " Three"; $this->words["4"] = " Four";
$this->words["5"] = " Five"; $this->words["6"] = " Six";
$this->words["7"] = " Seven"; $this->words["8"] = " Eight";
$this->words["9"] = " Nine";
$this->words["10"] = " Ten"; $this->words["11"] = " Eleven";
$this->words["12"] = " Twelve"; $this->words["13"] = " Thirten";
$this->words["14"] = " Fourten"; $this->words["15"] = " Fiften";
$this->words["16"] = " Sixten"; $this->words["17"] = " Seventen";
$this->words["18"] = " Eighten"; $this->words["19"] = " Nineten";
$this->words["20"] = " Twenty"; $this->words["30"] = " Thirty";
$this->words["40"] = " Forty"; $this->words["50"] = " Fifty";
$this->words["60"] = " Sixty"; $this->words["70"] = " Seventy";
$this->words["80"] = " Eighty"; $this->words["90"] = " Ninety";
$this->places[0] = " BDT";
$this->places[1] = " Hundred";
$this->places[2] = " Thousand";
$this->places[3] = " Lac";
$this->places[4] = " Crore";}
break;
case 'bn':
{
$this->words["1"] = " à¦à¦"; $this->words["2"] = " দà§à¦";
$this->words["3"] = " তিন"; $this->words["4"] = " à¦à¦¾à¦°";
$this->words["5"] = " পাà¦"; $this->words["6"] = " à¦à§";
$this->words["7"] = " সাত"; $this->words["8"] = " à¦à¦";
$this->words["9"] = " নà§";
$this->words["10"] = " দশ"; $this->words["11"] = " à¦à¦à¦¾à¦°à§";
$this->words["12"] = " বারà§"; $this->words["13"] = " তà§à¦°à§";
$this->words["14"] = " à¦à§à¦¦à§à¦¦"; $this->words["15"] = " পনà§à¦°";
$this->words["16"] = " ষà§à¦²"; $this->words["17"] = " সতà§à¦°";
$this->words["18"] = " à¦à¦ ার"; $this->words["19"] = " à¦à¦¨à¦¿à¦¶";
$this->words["21"] = " à¦à¦à§à¦¶"; $this->words["21"] = " বাà¦à¦¶";
$this->words["22"] = " বারà§"; $this->words["23"] = " তà§à¦à¦¶";
$this->words["24"] = " à¦à¦¬à§à¦¬à¦¿à¦¶"; $this->words["25"] = " পà¦à¦¿à¦¶";
$this->words["26"] = " à¦à¦¾à¦¬à§à¦¬à¦¿à¦¶"; $this->words["27"] = " সাতাশ";
$this->words["28"] = " à¦à¦ াশ"; $this->words["29"] = " à¦à¦¨à¦¤à§à¦°à¦¿à¦¶";
$this->words["41"] = " à¦à¦à¦à¦²à§à¦²à¦¿à¦¶"; $this->words["42"] = " বিà§à¦¾à¦²à§à¦²à¦¿à¦¶";
$this->words["43"] = " তà§à¦¤à¦¾à¦²à§à¦²à¦¿à¦¶"; $this->words["44"] = " à¦à§à§à¦¾à¦²à§à¦²à¦¿à¦¶";
$this->words["45"] = " পà§à¦¤à¦¾à¦²à§à¦²à¦¿à¦¶"; $this->words["46"] = " à¦à§à¦à¦²à§à¦²à¦¿à¦¶";
$this->words["47"] = " সাতà¦à¦²à§à¦²à¦¿à¦¶"; $this->words["48"] = " à¦à¦à¦à¦²à§à¦²à¦¿à¦¶";
$this->words["49"] = " à¦à¦¨à¦ªà¦à§à¦à¦¾à¦¶"; $this->words["51"] = " à¦à¦à¦¾à¦¨à§à¦¨";
$this->words["52"] = " বাহানà§à¦¨"; $this->words["53"] = " তিপানà§à¦¨ ";
$this->words["54"] = " à¦à§à§à¦¾à¦¨à§à¦¨"; $this->words["55"] = " পà¦à§à¦à¦¾à¦¨à§à¦¨";
$this->words["56"] = " à¦à¦¾à¦ªà¦¾à¦¨à¦¨"; $this->words["57"] = " সাতানà§à¦¨";
$this->words["58"] = " à¦à¦à¦¾à¦¨à§à¦¨"; $this->words["59"] = " à¦à¦¨à¦·à¦¾à¦";
$this->words["61"] = " à¦à¦à¦·à¦à§à¦à¦¿"; $this->words["62"] = " বাষà¦à§à¦à¦¿";
$this->words["63"] = " তà§à¦·à¦à§à¦à¦¿"; $this->words["64"] = " à¦à§à¦·à¦à§à¦à¦¿";
$this->words["65"] = " পà§à¦·à¦à§à¦à¦¿"; $this->words["66"] = " à¦à§à¦·à¦à§à¦à¦¿";
$this->words["67"] = " সাতষà¦à§à¦à¦¿"; $this->words["68"] = " à¦à¦à¦·à¦à§à¦à¦¿";
$this->words["69"] = " à¦à¦¨à¦¸à¦¤à§à¦¤à¦°"; $this->words["71"] = " à¦à¦à¦¾à¦¤à§à¦¤à¦°";
$this->words["72"] = " বাহাতà§à¦¤à¦°"; $this->words["73"] = " তিহাতà§à¦¤à¦° ";
$this->words["74"] = " à¦à§à§à¦¾à¦¤à§à¦¤à¦°"; $this->words["75"] = " পà¦à¦¾à¦¤à§à¦¤à¦°";
$this->words["76"] = " à¦à¦¿à§à¦¾à¦¤à§à¦¤à¦°"; $this->words["77"] = " সাতাতà§à¦¤à¦°";
$this->words["78"] = " à¦à¦à¦¾à¦¤à§à¦¤à¦°"; $this->words["79"] = " à¦à¦¨à¦à¦¶à¦¿";
$this->words["81"] = " à¦à¦à¦¾à¦à¦¶à¦¿"; $this->words["82"] = " বিরাà¦à¦¶à¦¿";
$this->words["83"] = " তিরাà¦à¦¶"; $this->words["84"] = " à¦à§à¦°à¦¾à¦à¦¶à¦¿";
$this->words["85"] = " পà¦à¦¾à¦à¦¶à¦¿"; $this->words["86"] = " à¦à¦¿à§à¦¾à¦à¦¶à¦¿";
$this->words["87"] = " সাতাà¦à¦¶à¦¿"; $this->words["88"] = " à¦à¦à¦¾à¦à¦¶à¦¿";
$this->words["89"] = " à¦à¦¨à¦¨à¦¬à§à¦¬à¦"; $this->words["91"] = " à¦à¦à¦¾à¦¨à¦¬à§à¦¬à¦";
$this->words["92"] = " বিরানবà§à¦¬à¦"; $this->words["93"] = " তিরানবà§à¦¬à¦";
$this->words["94"] = " à¦à§à¦°à¦¾à¦¨à¦¬à§à¦¬à¦"; $this->words["95"] = " পà¦à¦¾à¦¨à¦¬à§à¦¬à¦";
$this->words["96"] = " à¦à¦¿à§à¦¾à¦¨à¦¬à§à¦¬à¦"; $this->words["97"] = " সাতানবà§à¦¬à¦";
$this->words["98"] = " à¦à¦à¦¾à¦¨à¦¬à§à¦¬à¦"; $this->words["99"] = " নিরানবà§à¦¬à¦";
$this->words["20"] = " বিশ"; $this->words["30"] = " তà§à¦°à¦¿à¦¶";
$this->words["40"] = " à¦à¦²à§à¦²à¦¿à¦¶"; $this->words["50"] = " পà¦à§à¦à¦¾à¦¶";
$this->words["60"] = " ষাà¦"; $this->words["70"] = " সতà§à¦¤à¦°";
$this->words["80"] = " à¦à¦¶à¦¿"; $this->words["90"] = " নবà§à¦¬à¦";
$this->words["100"] = " বিশ"; $this->words["200"] = " তà§à¦°à¦¿à¦¶";
$this->words["300"] = " à¦à¦²à§à¦²à¦¿à¦¶"; $this->words["400"] = " পà¦à§à¦à¦¾à¦¶";
$this->words["500"] = " ষাà¦"; $this->words["600"] = " সতà§à¦¤à¦°";
$this->words["700"] = " à¦à¦¶à¦¿"; $this->words["800"] = " বিশ";
$this->words["900"] = " à¦à¦¶à¦¿";
$this->places[0] = " à¦à¦¾à¦à¦¾";
$this->places[1] = " শত";
$this->places[2] = " হাà¦à¦¾à¦°";
$this->places[3] = " লাà¦";
$this->places[4] = " à¦à§à¦à¦¿";}
break;
}
}
}
?>