note 34210 deleted from ref.strings by tomsommer
| From: | tomsommer@php.net | Date: | Wed, 15 Sep 2004 20:46:33 +0000 |
| Subject: | note 34210 deleted from ref.strings by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-76782@lists.php.net to get a copy of this message | ||
Note Submitter: lille dot findus at telia dot com
----
The first function to return 1st, 2nd etc was very ineffective, the second one don't work (try
21 for example).
Here's one that works(not too optimized though):
function nth($in)
{
if(strlen($in)>1 && substr($in,-2,1)==1)
return $in."th";
switch(substr($in,-1,1))
{
case 1:
return $in."st";
case 2:
return $in."nd";
case 3:
return $in."rd";
default:
return $in."th";
}
}