-
-
Save pierreburel/b6f9c5fb317a2504b35d140b928e6887 to your computer and use it in GitHub Desktop.
Smarty ordinal modifier plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Gets the ordinal for a number | |
* | |
* @param integer $number | |
* @return string | |
*/ | |
function smarty_modifier_ordinal($number) | |
{ | |
$number = intval($number); | |
if (!in_array(($number % 100), array(11, 12, 13))) { | |
switch ($number % 10) { | |
case 1: return $number . 'st'; | |
case 2: return $number . 'nd'; | |
case 3: return $number . 'rd'; | |
} | |
} | |
return $number . 'th'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This one doesn't show
12nd
like the original did.