Anonymous - Fri, 31/08/2012 - 00:54

Permalink

After looking at different solutions, I thought it would be better to just use the functions built into PHP. Not sure if this is more efficient, but it's certainly less code and works every time.


<?php
function ordinal($int)
{
  $two = substr($int, -2);
  $day = $two < 32 ? $two : '2' . substr($two, -1);
  $suffix = date('S', strtotime('May ' . $day));
  return $int . $suffix;
}
?>

CAPTCHA