From 03a1eac3b7bed8ed6df59109364a3eebe3f1cceb Mon Sep 17 00:00:00 2001 From: George Petculescu Date: Thu, 20 Oct 2016 21:03:38 +0300 Subject: ordinal_format will accept only non-negative natural numbers and return original value on failure + docs update regarding this. --- system/helpers/inflector_helper.php | 4 ++-- user_guide_src/source/helpers/inflector_helper.rst | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index c71516564..04e178aec 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -286,9 +286,9 @@ if ( ! function_exists('ordinal_format')) */ function ordinal_format($number) { - if ( ! ctype_digit((string) $number) OR $number < 0) + if ( ! ctype_digit((string) $number) OR $number < 1) { - return FALSE; + return $number; } $last_digit = array( diff --git a/user_guide_src/source/helpers/inflector_helper.rst b/user_guide_src/source/helpers/inflector_helper.rst index 8a6ca7a92..76cce6f4d 100644 --- a/user_guide_src/source/helpers/inflector_helper.rst +++ b/user_guide_src/source/helpers/inflector_helper.rst @@ -97,15 +97,16 @@ The following functions are available: .. php:function:: ordinal_format($number) - :param int $number: natural number to be converted - :returns: Ordinal numeral for given number or FALSE on failure + :param int $number: non-negative natural number to be converted + :returns: Ordinal numeral for given number or original value on failure :rtype: string - Returns the ordinal numeral (0th, 1st, 2nd, 3rd etc.) for a - natural number. If the input is not a natural number, the - function will return boolean FALSE. Examples:: + Returns the ordinal numeral (1st, 2nd, 3rd etc.) for a + non-negative natural number. If the input is not a natural number + greater than 0, the function will return the original value. Examples:: echo ordinal_format(1); // Returns 1st echo ordinal_format(3); // Returns 3rd echo ordinal_format(21); // Returns 21st echo ordinal_format(102); // Returns 102nd + echo ordinal_format(-5); // Invalid input, will return -5 -- cgit v1.2.3-24-g4f1b