Numbers to Words in PHP using PEAR package

pradeep's Avatar author of Numbers to Words in PHP using PEAR package
This is an article on Numbers to Words in PHP using PEAR package in PHP.
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's Avatar, Join Date: Feb 2007
Light Poster
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's Avatar, Join Date: Feb 2007
Light Poster
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's Avatar, Join Date: Apr 2005
Team Leader
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's Avatar, Join Date: Feb 2007
Newbie Member
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;
}

Last edited by shabbir; 16Feb2007 at 22:08.. Reason: Code formatting.
aswini_1978's Avatar, Join Date: Feb 2007
Light Poster
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