WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Numbers to words
Categories : PHP, PHP Classes Click here to Update Your Picture
glen mc arthur
Date : Nov 11th 2005
Grade : 3 of 5 (graded 4 times)
Viewed : 10404
File : No file for this code example.
Images : No Images for this code example.
Search : More code by glen mc arthur
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php 
/*********************************************** 
  * Example Name : Num2Words                    * 
  * Scripted By  : Glen Mc Arthur               * 
  * Email        : glen.mcarthur@gmail.com      * 
  * License      : GPL (Gnu Public License)     * 
  ***********************************************/   
  // START CONVERTION CLASS 

 
class num2words
    var
$numb = Array(); 
    var
$tail
    var
$number
    var
$currency
    var
$min
    function
num2words () { 
     
$this->numb = Array (""
                           
"one"
                           
"two"
                           
"three"
                           
"four"
                           
"five"
                           
"six"
                           
"seven"
                           
"eight"
                           
"nine"); 
    } 
    function
mod($a,$b) { 
      return
$a-$b*floor($a/$b); 
    } 
    function
setTail($str) { 
     
$this->tail = $str
    } 
    function
setNumber($int) { 
     
$int = trim($int); 
      if (
is_int(strpos($int,"-"))) { 
       
$this->number = substr($int,strpos($int,"-")+1,strlen($int)); 
       
$this->currency = "minus"
      } else { 
       
$this->number = $int
      } 
     
$this->setAsCurrency(); 
    } 
    function
getCurrency() { 
      return
$this->currency
    } 
    function
printCurrency() { 
      print
ucfirst(strtolower(trim($this->currency))); 
    } 
    function
setAsCurrency() { 
     
$xpos = strpos($this->number,"."); 
      if (
is_int($xpos)) { 
       
$pecahan = round(substr($this->number,$xpos,strlen($this->number)),2); 
       
$sisa = substr($this->number,0,$xpos); 
      } else { 
       
$pecahan = ""
       
$sisa    = $this->number
      } 
      if (
$sisa==0 || $this->number==0) { 
       
$this->currency .= "zero ".$this->tail
      } else { 
       
$trilion = floor($sisa/pow(10,12)); 
       
$sisa    = $this->mod($sisa,1000000000000); 

       
$billion = floor($sisa/pow(10,9)); 
       
$sisa    = $this->mod($sisa,1000000000); 

       
$million = floor($sisa/pow(10,6)); 
       
$sisa    = $this->mod($sisa,1000000); 

       
$thousand = floor($sisa/pow(10,3)); 
       
$sisa     = $this->mod($sisa,1000); 

       
$words    = $this->ThreeDigit($trilion, "trilion"); 
       
$words   .= $this->ThreeDigit($billion, "billion"); 
       
$words   .= $this->ThreeDigit($million, "million"); 
       
$words   .= $this->ThreeDigit($thousand, "thousand"); 
       
$words   .= $this->ThreeDigit($sisa,""); 
       
$words   .= " ".$this->tail
      } 
      if (
$pecahan>0) { 
       
$words .= " and". $this->ThreeDigit(round($pecahan*100),"sen"); 
      } 
     
$this->currency .= strtolower($words); 
    } 
    function
ThreeDigit($amount, $suffix="") { 
     
$sisa = (int) $amount
     
$words = ""
      if (
$sisa < 20 && $sisa > 10) { 
        if (
$sisa==11) { 
         
$words = " eleven"
        } elseif (
$sisa == 12) { 
         
$words = " twelve"
        } elseif (
$sisa == 13) { 
         
$words = " thirteen"
        } elseif (
$sisa == 15) { 
         
$words = " fifteen"
        } elseif (
$sisa == 18) { 
         
$words = " eighteen"
        } else { 
         
$words = " ".$this->numb[$sisa-10]."teen"
        } 
        if (
$suffix != "") { 
         
$words .= " ".$suffix
        } 
        return
$words
      } 
     
$ratus = floor($sisa/100); 
      if (
$ratus <= 0) { 
       
$words .= ""
      } else { 
       
$words .= " ".$this->numb[$ratus]." hundred"
      } 
     
$sisa = $this->mod($sisa,100); 
      if (
$sisa < 20 && $sisa > 10) { 
        if (
$sisa == 11) { 
         
$words .= " eleven ". $suffix
        } elseif (
$sisa == 12) { 
         
$words .= " twelve"
        } elseif (
$sisa == 13) { 
         
$words .= " thirteen"
        } elseif (
$sisa == 15) { 
         
$words .= " fifteen"
        } elseif (
$sisa == 18) { 
         
$words .= " eighteen"
        } else { 
         
$words .= " ".$this->numb[$sisa-10]."teen ". $suffix
        } 
        return
$words
      } 
     
$puluh = floor($sisa/10); 
      if (
$puluh == 0) { 
       
$words .= ""
      } elseif (
$puluh == 1) { 
       
$words .= " ten"
      } elseif (
$puluh == 2) { 
       
$words .= " twenty"
      } elseif (
$puluh == 3) { 
       
$words .= " thirty"
      } elseif (
$puluh == 5) { 
       
$words .= " fifty"
      } elseif (
$puluh == 5) { 
       
$words .= " eighty"
      } else { 
       
$words .= " ".$this->numb[$puluh]."ty"
      } 
     
$sisa = $this->mod($sisa,10); 
      if (
$sisa>0&&$sisa<=9) { 
       
$words .= " ".$this->numb[$sisa]; 
      } 
      if (
$amount>0&&$amount<=1000) { 
       
$words .= " ".$suffix
      } 
      return
$words
    } 
  }
 
// END CONVERTION CLASS
?>



XPath for PHP without the DOM XML extension
Categories : DOM XML, XML, XSLT, PHP Classes, PHP
Convert SQL from oracle,mysql,mssql,sqlite and odbc to SQL compatible
Categories : PHP, PHP Classes, Databases, MySQL, MS SQL Server
STR - a Perl-like string manipulator class - The str class provides 4 perl-like methods for manipulating strings and other scalar variables.
Categories : PHP, PHP Classes, Perl, Strings
Email Class
Categories : PHP, Mail, PHP Classes
SQLite PHP Database Wrapper
Categories : PHP, PHP Classes, Databases, SQLite, Beginner Guides
[PHP5] PHP Debugger and Helper
Categories : PHP, PHP Classes, Errors and Logging, Debugging, XML
EasyPhpThumbnail Class - The EasyPhpThumbnail class allows you to generate thumbnails and handle image manipulation for GIF, JPG and PNG on-the-fly.
Categories : PHP, PHP Classes, Object Oriented, Graphics, GD image library
Powerful php/mysql Pagination for up to 6 URL Params
Categories : PHP, PHP Classes, Databases, MySQL, Navigation
Generate FDF files without the pdftk library or php extension.
Categories : PHP, PHP Classes, PDF
Simple Maiing list with newsletter support
Categories : PHP, PHP Classes, Mail
Gonx URLs - This class is meant to generate URLs for accessing application dynamically generated pages based on parameters passed in the URL.
Categories : PHP, PHP Classes, Navigation, URLs
Antispoof - a class to help prevent people hi-jacking and misusing parts of a website
Categories : PHP, PHP Classes, Security
cPanel Subdomains Creator - Create cPanel subdomains without logging into cPanel. Let your visitors create their own subdomains without your intervention. Moreover, it will inform if a subdomain is already exists.
Categories : PHP, Web Services, PHP Classes
XTemplate, a template class for PHP
Categories : PHP Classes, HTML and PHP, PHP
Writing Portable MySQL Code in PHP: Porting to Oracle, Microsoft SQL Server, Sybase, Interbase, PostgreSQL and other databases using ADODB class library.
Categories : MySQL, PHP, PHP Classes, ODBC, General SQL
 matthew waygood wrote :1362
As with most number as text functions this has been written for Americans. It would be nice to include the option to specify the rest of the world too.

ie 1,000,000 is one million
however 1,000,000,000 in the US is a billion, but to everyone else its just a thousand million.
1,000,000,000,000 is a trillion, and to everyone else a billion.
This works on BI meaning two, as in bicycle, so a billion is 2 lots of a million hense 12 (2x6) zeros.
Probably done by Webster who standardised English with an emphasis on Phonetics. eg. Colour/Color