note 45709 added to ref.strings

From: Date: Wed, 15 Sep 2004 19:56:22 +0000
Subject: note 45709 added to ref.strings
Groups: php.notes 
Request: Send a blank email to php-notes+get-76773@lists.php.net to get a copy of this message
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; } ?> ---- Manual Page -- http://www.php.net/manual/en/ref.strings.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45709 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45709&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45709&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#76773) next »