Posted By

galofre on 06/30/10


Tagged

numbers st nd rd th


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

dantreacy
FedericoBiccheddu
convergine
rocktronica


st, nd, rd, th to Number


 / Published in: PHP
 

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

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

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Vordreller on June 30, 2010

And what are st, nd, rd, th

?

You need to login to post a comment.