Return to Snippet

Revision: 28083
at June 30, 2010 15:47 by galofre


Initial Code
function ordinal($n) {
    $ln = (int) substr($n, -1);
    $sln = (int) substr($n, -2);
    $r = array('st','nd','rd');
    $es = (($sln < 11 || $sln > 19) && $ln > 0 && $ln < 4);
    return $n . ($es ? $r[$ln - 1] : 'th');
  }

Initial URL

                                

Initial Description
Add  st, nd, rd, th to any particular number

Initial Title
st, nd, rd, th to Number

Initial Tags

                                

Initial Language
PHP