Go4Expert

Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/articles/php-tutorials/)
-   -   Numbers to Words in PHP using PEAR package (http://www.go4expert.com/articles/words-php-using-pear-package-t1847/)

pradeep 9Nov2006 18:26

Numbers to Words in PHP using PEAR package
 
Some web applications need to display numbers in words, like e-commerce, shopping web applications, so PEAR brings a package named Numbers_Words which converts numbers to words in 2 lines of PHP code.
Checkout the example below.

Code: PHP

<?php
 require('Numbers/Words.php');
 
     $number = 100254;
     $nw = new Numbers_Words();
     $numw = $nw->toWords($number);
 
     print $numw;
 ?>


Output:
Code:

one hundred thousand two hundred fifty-four
More can be done with with Numbers_Words, like setting the locale so that the output is formatted according to the local, you can find Numbers_Words documentation here.

aswini_1978 15Feb2007 12:13

Re: Numbers to Words in PHP using PEAR package
 
Dear Sandeep,

I would highly appreciate if u can help me by solve this query??

I am trying to convert number to words and for that I have to download the file

Numbers_Words.php from pear package.

But this file is not opening. Can u please tell me how to download this file so that I may use the function that u have mentioned.

THANKS A TON IN ADVANCE..

Warm regards,
Aswini
Delhi

aswini_1978 15Feb2007 12:15

Re: Numbers to Words in PHP using PEAR package
 
Dear Pradeep,

I would highly appreciate if u can help me by solve this query??

I am trying to convert number to words and for that I have to download the file

Numbers_Words.php from pear package.

But this file is not opening. Can u please tell me how to download this file so that I may use the function that u have mentioned.

THANKS A TON IN ADVANCE..

Warm regards,
Aswini
Delhi[/QUOTE]

pradeep 15Feb2007 12:22

Re: Numbers to Words in PHP using PEAR package
 
Firstly you need to install PEAR, you'll find the instructions here http://pear.php.net/manual/en/installation.getting.php

then you need to install the Numbers_Words package using the PEAR installer.You'll find the instructions here http://pear.php.net/manual/en/installation.cli.php

01soft 16Feb2007 19:52

Re: Numbers to Words in PHP using PEAR package
 
try visit this code
from http://www.reconn.us/count_words.html
Code:

function adv_count_words($str)
{
  $words = 0;
  $str = eregi_replace(" +", " ", $str);
  $array = explode(" ", $str);
  for($i=0;$i < count($array);$i++)
  {
    if (eregi("[0-9A-Za-z---]", $array[$i]))
      $words++;
  }
  return $words;
}


aswini_1978 31May2007 13:34

Re: Numbers to Words in PHP using PEAR package
 
Hi
Can u pls let me know how to calculate no. of weeks between 2 dates as I have to make MIS report on the basisi of weeks.

That means weekly report of collections.

Thanks a ton in advance

pradeep 31May2007 14:18

Re: Numbers to Words in PHP using PEAR package
 
Refer to these threads

http://www.go4expert.com/showthread.php?t=3494
http://www.go4expert.com/showthread.php?t=2769


All times are GMT +5.5. The time now is 20:49.