note 92547 modified in function.date by danbrown

From: Date: Wed, 29 Jul 2009 03:12:01 +0000
Subject: note 92547 modified in function.date by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-158853@lists.php.net to get a copy of this message
Haven't really tested it performance-wise vs. other methods, but I thought I'd post this anyways... Here's a nifty way to exploit date()'s built-in ordinal suffix calculator to append the proper ordinal suffix to an arbitrary number: <?php function addOrdinal($num=0){ return $num.(((strlen($num)>1)&&(substr($num,-2,1)=='1'))? 'th' : date("S",mktime(0,0,0,0,substr($num,-1),0))); } // end function addOrdinal ?> --was-- Haven't really tested it performance-wise vs. other methods, but I thought I'd post this anyways... Here's a nifty way to exploit date()'s built-in ordinal suffix calculator to append the proper ordinal suffix to an arbitrary number: function addOrdinal($num=0){ return $num.(((strlen($num)>1)&&(substr($num,-2,1)=='1'))? 'th' : date("S",mktime(0,0,0,0,substr($num,-1),0))); } // end function addOrdinal http://php.net/manual/en/function.date.php

« previous php.notes (#158853) next »