The Inflector Helper file contains functions that permits you to change English words to plural, singular, camel case, etc.
This helper is loaded using the following code:
$this->load->helper('inflector');
The following functions are available:
singular($str)
Parameters: |
|
---|---|
Returns: |
A singular word |
Return type: |
string |
Changes a plural word to singular. Example:
echo singular('dogs'); // Prints 'dog'
plural($str)
Parameters: |
|
---|---|
Returns: |
A plural word |
Return type: |
string |
Changes a singular word to plural. Example:
echo plural('dog'); // Prints 'dogs'
camelize($str)
Parameters: |
|
---|---|
Returns: |
Camelized string |
Return type: |
string |
Changes a string of words separated by spaces or underscores to camel case. Example:
echo camelize('my_dog_spot'); // Prints 'myDogSpot'
underscore($str)
Parameters: |
|
---|---|
Returns: |
String containing underscores instead of spaces |
Return type: |
string |
Takes multiple words separated by spaces and underscores them. Example:
echo underscore('my dog spot'); // Prints 'my_dog_spot'
humanize($str[, $separator = '_'])
Parameters: |
|
---|---|
Returns: |
Humanized string |
Return type: |
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'
is_countable($word)
Parameters: |
|
---|---|
Returns: |
TRUE if the word is countable or FALSE if not |
Return type: |
bool |
Checks if the given word has a plural version. Example:
is_countable('equipment'); // Returns FALSE
© 2014–2016 British Columbia Institute of Technology
Licensed under the MIT License.
https://www.codeigniter.com/user_guide/helpers/inflector_helper.html