note 63193 added to function.number-format
| From: | chris_cember at cinmach dot com | Date: | Wed, 15 Mar 2006 21:40:23 +0000 |
| Subject: | note 63193 added to function.number-format | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-105875@lists.php.net to get a copy of this message | ||
// the mktime shortcut is a little trickier than it would first appear, even with a mod...
function text_number($n) {
$mod = $n % (($n > 20)?10:20);
return $n . (($mod==0)?"th":date("S",mktime(0,0,0,1,$mod,2000)));
}
// or for those who don't appreciate shorthand:
function text_number($n) {
if ($n > 20) {
$mod_factor = 10;
} else {
$mod_factor = 20;
}
$mod = $n % $mod_factor;
if ($mod == 0) {
$txt = "th";
} else {
$txt = date("S",mktime(0,0,0,1,$mod,2000));
}
return $n . $txt;
}
/*
one issue comes up in numbers that mod to zero (which mktime will associate with the 31st of
December, 1999). another issue is between 23rd and 13rd, err I mean 13th. If you use 20 (or even
30) all the time, however, you'll end up with 33th (or 43th).
*/
----
Server IP: 216.194.113.175
Probable Submitter: 216.68.243.12 (proxied: 1.0 W2KISA)
----
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/63193
Del: integrated -- http://master.php.net/note/delete/63193/integrated
Del: useless -- http://master.php.net/note/delete/63193/useless
Del: bad code -- http://master.php.net/note/delete/63193/bad+code
Del: spam -- http://master.php.net/note/delete/63193/spam
Del: non-english -- http://master.php.net/note/delete/63193/non-english
Del: in docs -- http://master.php.net/note/delete/63193/in+docs
Del: other reasons-- http://master.php.net/note/delete/63193
Reject -- http://master.php.net/note/reject/63193
Search -- http://master.php.net/manage/user-notes.php