note 62478 added to function.number-format
| From: | mikesabatino at gmail dot com | Date: | Wed, 01 Mar 2006 15:34:03 +0000 |
| Subject: | note 62478 added to function.number-format | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-104637@lists.php.net to get a copy of this message | ||
<?php
# Function to represent a number like '2nd', '10th', '101st' etc
function text_number($n)
{
# Array holding the teen numbers. If the last 2 numbers of $n are in this array, then we'll
add 'th' to the end of $n
$teen_array = array(11, 12, 13, 14, 15, 16, 17, 18, 19);
# Array holding all the single digit numbers. If the last number of $n, or if $n itself, is a key
in this array, then we'll add that key's value to the end of $n
$single_array = array(1 => 'st', 2 => 'nd', 3 => 'rd', 4
=> 'th', 5 => 'th', 6 => 'th', 7 => 'th', 8
=> 'th', 9 => 'th', 0 => 'th');
# Store the last 2 digits of $n in order to check if it's a teen number.
$if_teen = substr($n, -2, 2);
# Store the last digit of $n in order to check if it's a teen number. If $n is a single digit,
$single will simply equal $n.
$single = substr($n, -1, 1);
# If $if_teen is in array $teen_array, store $n with 'th' concantenated onto the end of
it into $new_n
if ( in_array($if_teen, $teen_array) )
{
$new_n = $n . 'th';
}
# $n is not a teen, so concant the appropriate value of it's $single_array key onto the end of
$n and save it into $new_n
elseif ( $single_array[$single] )
{
$new_n = $n . $single_array[$single];
}
# Return new
return $new_n;
}
?>
----
Server IP: 216.194.113.175
Probable Submitter: 206.231.8.9
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.number-format.php
Edit -- http://master.php.net/note/edit/62478
Del: integrated -- http://master.php.net/note/delete/62478/integrated
Del: useless -- http://master.php.net/note/delete/62478/useless
Del: bad code -- http://master.php.net/note/delete/62478/bad+code
Del: spam -- http://master.php.net/note/delete/62478/spam
Del: non-english -- http://master.php.net/note/delete/62478/non-english
Del: in docs -- http://master.php.net/note/delete/62478/in+docs
Del: other reasons-- http://master.php.net/note/delete/62478
Reject -- http://master.php.net/note/reject/62478
Search -- http://master.php.net/manage/user-notes.php