/ Published in: PHP
If you want to transform an int number to a position number (ie. 1 = 1st, 6 = 6th etc..)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function make_position($position) { if( $last > 3 || $last == 0 ) $ext = 'th'; else if( $last == 3 ) $ext = 'rd'; else if( $last == 2 ) $ext = 'nd'; else $ext = 'st'; if( $last == 1 && $seclast == 1) $ext = 'th'; if( $last == 2 && $seclast == 1) $ext = 'th'; if( $last == 3 && $seclast == 1) $ext = 'th'; return $position.$ext; } eg. make_position(2); // 2nd eg. make_position(8); // 8th eg. make_position(21); // 21st eg. make_position(23); // 23rd