summaryrefslogtreecommitdiffstats
path: root/system/helpers/inflector_helper.php
diff options
context:
space:
mode:
authorGeorge Petculescu <gxgpet@gmail.com>2016-10-20 19:53:11 +0200
committerGeorge Petculescu <gxgpet@gmail.com>2016-10-20 19:53:11 +0200
commit11954d2521475f6964bfa9c65dcd2f3e53a65af5 (patch)
tree972c7e4f0d4ea7c29d5dd1b253be4e7fdadecef3 /system/helpers/inflector_helper.php
parent7de46d4d99017b42ba172cebff8998163ee6295f (diff)
moved ordinal_format() helper function from Number helper to Inflector helper
Diffstat (limited to 'system/helpers/inflector_helper.php')
-rw-r--r--system/helpers/inflector_helper.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php
index 6dc3b5030..c71516564 100644
--- a/system/helpers/inflector_helper.php
+++ b/system/helpers/inflector_helper.php
@@ -273,3 +273,43 @@ if ( ! function_exists('is_countable'))
);
}
}
+
+// ------------------------------------------------------------------------
+
+if ( ! function_exists('ordinal_format'))
+{
+ /**
+ * Returns the English ordinal numeral for a given number
+ *
+ * @param int $number
+ * @return string
+ */
+ function ordinal_format($number)
+ {
+ if ( ! ctype_digit((string) $number) OR $number < 0)
+ {
+ return FALSE;
+ }
+
+ $last_digit = array(
+ 0 => 'th',
+ 1 => 'st',
+ 2 => 'nd',
+ 3 => 'rd',
+ 4 => 'th',
+ 5 => 'th',
+ 6 => 'th',
+ 7 => 'th',
+ 8 => 'th',
+ 9 => 'th'
+ );
+ if (($number % 100) >= 11 && ($number % 100) <= 13)
+ {
+ return $number.'th';
+ }
+ else
+ {
+ return $number.$last_digit[$number % 10];
+ }
+ }
+} \ No newline at end of file