blob: ca781d2adaf42077b74a30b967460a10c2381aec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
################
Inflector Helper
################
The Inflector Helper file contains functions that permits you to change
**English** words to plural, singular, camel case, etc.
.. contents::
:local:
.. raw:: html
<div class="custom-index container"></div>
Loading this Helper
===================
This helper is loaded using the following code::
$this->load->helper('inflector');
Available Functions
===================
The following functions are available:
.. php:function:: singular($str)
:param string $str: Input string
:returns: A singular word
:rtype: string
Changes a plural word to singular. Example::
echo singular('dogs'); // Prints 'dog'
.. php:function:: plural($str)
:param string $str: Input string
:returns: A plural word
:rtype: string
Changes a singular word to plural. Example::
echo plural('dog'); // Prints 'dogs'
.. php:function:: camelize($str)
:param string $str: Input string
:returns: Camelized string
:rtype: string
Changes a string of words separated by spaces or underscores to camel
case. Example::
echo camelize('my_dog_spot'); // Prints 'myDogSpot'
.. php:function:: underscore($str)
:param string $str: Input string
:returns: String containing underscores instead of spaces
:rtype: string
Takes multiple words separated by spaces and underscores them.
Example::
echo underscore('my dog spot'); // Prints 'my_dog_spot'
.. php:function:: humanize($str[, $separator = '_'])
:param string $str: Input string
:param string $separator: Input separator
:returns: Humanized string
:rtype: string
Takes multiple words separated by underscores and adds spaces between
them. Each word is capitalized.
Example::
echo humanize('my_dog_spot'); // Prints 'My Dog Spot'
To use dashes instead of underscores::
echo humanize('my-dog-spot', '-'); // Prints 'My Dog Spot'
.. php:function:: word_is_countable($word)
:param string $word: Input string
:returns: TRUE if the word is countable or FALSE if not
:rtype: bool
Checks if the given word has a plural version. Example::
word_is_countable('equipment'); // Returns FALSE
.. note:: This function used to be called ``is_countable()`` in
in previous CodeIgniter versions.
.. php:function:: ordinal_format($number)
: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 (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
|