tibberous Posted August 23, 2008 Share Posted August 23, 2008 I made one, but is it build in somewhere? function ith($x){ return ($x == 1 ? '1st' : ($x == 2 ? '2nd' : ($x == 3 ? '3rd' : $x."th"))); } So you send it a number, and it converts to like 1st, 2nd, 3rd, 4th, ect? Quote Link to comment Share on other sites More sharing options...
unrelenting Posted August 23, 2008 Share Posted August 23, 2008 <?php function ordinal($cdnl){ $test_c = abs($cdnl) % 10; $ext = ((abs($cdnl) %100 < 21 && abs($cdnl) %100 > 4) ? 'th' : (($test_c < 4) ? ($test_c < 3) ? ($test_c < 2) ? ($test_c < 1) ? 'th' : 'st' : 'nd' : 'rd' : 'th')); return $cdnl.$ext; } ?> Quote Link to comment Share on other sites More sharing options...
papaface Posted August 23, 2008 Share Posted August 23, 2008 If you're doing this for a date just do: <?php $num = "31"; echo $num . date("S",mktime(0,0,0,0,$num)); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.