Numbers to Words in PHP using PEAR package

Discussion in 'PHP' started by pradeep, Nov 9, 2006.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    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.

    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.
     
  2. aswini_1978

    aswini_1978 New Member

    Joined:
    Feb 15, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  3. aswini_1978

    aswini_1978 New Member

    Joined:
    Feb 15, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    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]
     
  4. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
  5. 01soft

    01soft New Member

    Joined:
    Feb 16, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.softsea.com/
    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 a moderator: Feb 16, 2007
  6. aswini_1978

    aswini_1978 New Member

    Joined:
    Feb 15, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  7. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice