/ Published in: PHP
URL: http://www.misteroneill.com
This function takes a number and appends an ordinal suffix. By default, it uses the HTML tag around the suffix, but passing a Boolean false for the second parameter will not.
Expand |
Embed | Plain Text
function show_ordinal($num, $html = true) { $the_num = (string) $num; switch($last_digit) { case "1": $the_num .= ($html) ? '<sup>st</sup>' : 'st'; break; case "2": $the_num .= ($html) ? '<sup>nd</sup>' : 'nd'; break; case "3": $the_num .= ($html) ? '<sup>rd</sup>' : 'rd'; break; default: $the_num .= ($html) ? '<sup>th</sup>' : 'th'; } return $the_num; }
You need to login to post a comment.
