Skip to content

Instantly share code, notes, and snippets.

@tomschlick
Created January 16, 2011 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomschlick/781663 to your computer and use it in GitHub Desktop.
Save tomschlick/781663 to your computer and use it in GitHub Desktop.
php ordinal number helper function
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');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment