To add English ordinal number suffix after normal number, following php function returns number with proper suffix.
e.g. 1st, 2nd, 3rd, 4th, 5th, 6th…
For php versions prior to 5.3. use following version.
function number_to_ordinal ($number) { if($number===0) return '0'; else { $suffix = array('th','st','nd','rd','th','th','th','th','th','th'); if ((($number % 100) >= 11) && (($number%100) <= 13)) return $number. 'th'; else return $number. $suffix[$number % 10]; } }
For php 5.3+, using the built in php function and it is even better because works with locale, just provide your locale.
$locale = 'en_US'; $ordinal = new NumberFormatter($locale, NumberFormatter::ORDINAL); echo $ordinal->format($number);