note 45709 deleted from ref.strings by tomsommer

From: Date: Wed, 15 Sep 2004 20:45:35 +0000
Subject: note 45709 deleted from ref.strings by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-76779@lists.php.net to get a copy of this message
Note Submitter: Karl at apologetix dot com ---- Both of the above functions to ordinalize a number ignore the special case where if the number ends in TWO ones, it shouldn't be st, but th: 521st gets the st 511th gets the th!!! Here's my update to that. This is my first php project, and I've learned a ton!!!!! <? php function ordinalize($number) { $driver = substr("$number", -1); // special case: if it ends in 11, we say eleventh, three hundred and eleventh, etc. if (substr("$number",-2)=='11') { $number = $number . "th"; } else { switch($driver) { case '1': $number = $number . "st"; break; case '2': $number = $number . "nd"; break; case '3': $number = $number . "rd"; break; default: $number = $number . "th"; break; } } return $number; } ?>

« previous php.notes (#76779) next »