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? Link to comment https://forums.phpfreaks.com/topic/121048-way-to-convert-x-to-xth/ 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; } ?> Link to comment https://forums.phpfreaks.com/topic/121048-way-to-convert-x-to-xth/#findComment-623971 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)); ?> Link to comment https://forums.phpfreaks.com/topic/121048-way-to-convert-x-to-xth/#findComment-623972 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.