Blame | Letzte Änderung | Log anzeigen | RSS feed
** Introduction:With PEAR::Numbers_Words class you can change an integer numberto simple words. This can be usefull when you need to spell a currencyvalue e.g. on an invoice.You can choose between several languages (language files are locatedin Numbers/Words/ directory).BTW: if you need to change number to currency, use money_format()PHP function (available since 4.3 (not yet released)). But you mustknow that locale LC_MONETARY rules are sometimes unclear.** Getting started:First you need to install Numbers_Words PEAR package.You can do it (as root) with:pear install Numbers_WordsIn your php script you need to load Numbers/Words.php header file:require_once('Numbers/Words.php');Then you can call Numbers_Words::toWords() function with twoarguments: integer number (can be a string with digits) andoptional locale name (default is en_US):$ret = Numbers_Words::toWords($num,"en_GB");if (PEAR::isError($ret)) {echo "Error: " . $ret->message . "\n";} else {echo "Num $num in British English is '<b>$ret</b>'<p>\n";}For this would display:Num 12340000000 in British English is '<b>twelve thousand million three hundred forty million</b>'<p>** Current State:The current release can be found at the PEAR webpage:http://pear.php.net/package-info.php?package=Numbers_WordsFor the time of writting this Readme file, Numbers_spell package has thestatus beta, which means there can be samo bugs, and it is under development.This is not mature code.** DevelopmentThis package needs help from people, who can write language modules otherthan Polish and English.** Package Content:Readme.txt - this fileChangeLog - change logtest-numbers-words.php - test file showing Numbers_Words example usageWords.php - main class file, that loads language modules on demandWords/lang.{LOCALE_NAME}.php - language modulesThere are avaibale the following modules (called by locale name,in alphabetical order):bg - Bulgarian language (in WIN-1251 charset).Author: Kouber Saparevcs - Czech language.Author: Petr 'PePa' Pavelde - German language.Author: Piotr Klabandk - Danish language.Author: Jesper Veggerbyen_100 - Donald Knuth number naming system, in English language.Author: Piotr Klabanen_GB - British English notation of numbers, whereone billion is 1000000 times one million.1000 times million is just 'thousand million' here.I do not use a word billiard here, becauseEnglish people do not use it often, and even could not know it.Author: Piotr Klabanen_US - American English notation of numbers, whereone billion is 1000 times one millionAuthor: Piotr Klabanes - Spanish (Castellano) language.Author: Xavier Nogueres_AR - Argentinian Spanish language.Author: Martin Marreseet - Estonian language.Author: Erkki Saarniitfr - French language.Author: Kouber Saparevfr_BE - French (Belgium) language.Author: Kouber Saparev, Philippe Bajoithe - Hebrew language.Author: Hadar Porathu_HU - Hungarian language.Author: Nils Hompid - Indonesia language.Authors: Ernas M. Jamil, Arif Rifai Dwiyantoit_IT - Italian language.Authors: Filippo Beltramini, Davide Caironilt - Lithuanian language.Author: Laurynas Butkusnl - Dutch language.Author: WHAM van Dinterpl - Polish language (in an internet standard charset ISO-8859-2)Author: Piotr Klabanpt_BR - Brazilian Portuguese language.Authors: Marcelo Subtil Marcal and Mario H.C.T.ru - Russian language.Author: Andrey Demenevsv - Swedich language.Author: Robin Ericsson** What if numbers have fraction part?You can split the number by the coma or dot. The examplefunction was provided by Ernas M. Jamil (see below).I do not know if the splitting and concatenating numbersshould be supported by Numbers_Words ... Does each languagespell numbers with a 'coma'/'koma'? What do you think?function num2word($num, $fract = 0) {require_once('Numbers/Words.php');$num = sprintf("%.".$fract."f", $num);$fnum = explode('.', $num);$ret = Numbers_Words::toWords($fnum[0],"id");if(!$fract) return $ret;$ret .= ' koma '; // point in english$ret .= Numbers_Words::toWords($fnum[1],"id");return $ret;}** How to convert decimal part and not fraction part of the currency value?Rob King send me a patch that would allow to leave fraction part in digits.I.e. you can convert 31.01 into 'thirty-one pounds 01 pence':require_once('Numbers/Words.php');require_once('Numbers/Words/lang.en_GB.php');$obj = new Numbers_Words_en_GB;$convert_fraction = false;print $obj->toCurrencyWords('GBP', '31', '01', $convert_fraction) . "\n";** How to write new Language Files:Just copy existing en_US or en_GB etc. file into lang.{your_country/locale code}.phpand translate digits, numbers, tousands to your language. Then please send itto the author to the address makler@man.torun.pl.** CreditsAll changes from other people are desrcribed with details in ChangeLog.There are also names of the people who send me patches etc.Authors of the language files are mentioned in the language files directlyas the author.