|
|
|
|
|
|
Like this code?
Show the author your appreciation.
|
| |
Convert Number To Words
<?php
/***********************************************
* Script Name : NumToWords *
* Scripted By : Alex Culango *
* Email : [email protected] *
***********************************************/
function numtowords($num){
$ones = array(
1 => "one",
2 => "two",
3 => "three",
4 => "four",
5 => "five",
6 => "six",
7 => "seven",
8 => "eight",
9 => "nine",
10 => "ten",
11 => "eleven",
12 => "twelve",
13 => "thirteen",
14 => "fourteen",
15 => "fifteen",
16 => "sixteen",
17 => "seventeen",
18 => "eighteen",
19 => "nineteen"
);
$tens = array(
2 => "twenty",
3 => "thirty",
4 => "forty",
5 => "fifty",
6 => "sixty",
7 => "seventy",
8 => "eighty",
9 => "ninety"
);
$hundreds = array(
"hundred",
"thousand",
"million",
"billion",
"trillion",
"quadrillion"
); //limit t quadrillion
$num = number_format($num,2,".",",");
$num_arr = explode(".",$num);
$wholenum = $num_arr[0];
$decnum = $num_arr[1];
$whole_arr = array_reverse(explode(",",$wholenum));
krsort($whole_arr);
$rettxt = "";
foreach($whole_arr as $key => $i){
if($i < 20){
$rettxt .= $ones[$i];
}elseif($i < 100){
$rettxt .= $tens[substr($i,0,1)];
$rettxt .= " ".$ones[substr($i,1,1)];
}else{
$rettxt .= $ones[substr($i,0,1)]." ".$hundreds[0];
$rettxt .= " ".$tens[substr($i,1,1)];
$rettxt .= " ".$ones[substr($i,2,1)];
}
if($key > 0){
$rettxt .= " ".$hundreds[$key]." ";
}
}
if($decnum > 0){
$rettxt .= " and ";
if($decnum < 20){
$rettxt .= $ones[$decnum];
}elseif($decnum < 100){
$rettxt .= $tens[substr($decnum,0,1)];
$rettxt .= " ".$ones[substr($decnum,1,1)];
}
}
return $rettxt;
}
echo numtowords("23431999.99");
?> |
|
| Link Submition - Allow your visitors to submit links to the site. Categories : PHP, Arrays, Filesystem, Beginner Guides | | | Form Submission Using Array's Categories : PHP, HTML and PHP, Beginner Guides, Arrays | | | Selecting a random line from a text file Categories : PHP, Filesystem, Arrays, Beginner Guides | | | How to display any array in several rows and columns of a table. Not just
in one column or in alternate rows. This example shows a nice color table
generated with PHP, but can be used with any array values(e.g. Database) Categories : Arrays, PHP, Miscellaneous, Beginner Guides, Graphics | | | Beginners Array Functions Categories : PHP, Beginner Guides, Arrays | | | Human readable PHP password generator Categories : PHP, Security, Beginner Guides, Arrays | | | Random text quote Categories : PHP, Arrays, Beginner Guides | | | Looping through two arrays Categories : PHP, Databases, Arrays | | | Easy alert box pop-up function Categories : PHP, Java Script, Beginner Guides | | | Sort the results from a SELECT query (any number of columns) into an array automatically. Categories : PHP, PHP Classes, Arrays, Databases, MySQL | | | A very simple PHP single password cookie based login without usernames. Categories : PHP, Cookies, Security, Beginner Guides | | | How to preset a text string in a textarea input field Categories : HTML, HTML and PHP, PHP, Beginner Guides | | | PHP based HTML rabbing Tools Categories : PHP, HTML and PHP, Tag Extractors, Regexps, Beginner Guides | | | Stepping through a numbered array with each() and list() Categories : PHP, Arrays | | | PHP Image Validation Class - test if a specific file is of a certain image type without relying on the said file extension. Categories : PHP, PHP Classes, Data Validation, Graphics, Beginner Guides | |
| |
| |
|