The Inflector Helper file contains functions that permit you to change English words to plural, singular, camel case, etc.
This helper is loaded using the following code:
helper('inflector');
The following functions are available:
singular($string) | Parameters: |
|
|---|---|
| Returns: |
A singular word |
| Return type: |
string |
Changes a plural word to singular. Example:
echo singular('dogs'); // Prints 'dog'
plural($string) | Parameters: |
|
|---|---|
| Returns: |
A plural word |
| Return type: |
string |
Changes a singular word to plural. Example:
echo plural('dog'); // Prints 'dogs'
counted($count, $string) | Parameters: |
|
|---|---|
| Returns: |
A singular or plural phrase |
| Return type: |
string |
Changes a word and its count to a phrase. Example:
echo counted(3, 'dog'); // Prints '3 dogs'
camelize($string) | Parameters: |
|
|---|---|
| Returns: |
Camel case 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'
pascalize($string) | Parameters: |
|
|---|---|
| Returns: |
Pascal case string |
| Return type: |
string |
Changes a string of words separated by spaces or underscores to Pascal case, which is camel case with the first letter capitalized. Example:
echo pascalize('my_dog_spot'); // Prints 'MyDogSpot'
underscore($string) | 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($string[, $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_pluralizable($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_pluralizable('equipment'); // Returns false
dasherize($string) | Parameters: |
|
|---|---|
| Returns: |
Dasherized string |
| Return type: |
string |
Replaces underscores with dashes in the string. Example:
dasherize('hello_world'); // Returns 'hello-world'
ordinal($integer) | Parameters: |
|
|---|---|
| Returns: |
Ordinal suffix |
| Return type: |
string |
Returns the suffix that should be added to a number to denote the position such as 1st, 2nd, 3rd, 4th. Example:
ordinal(1); // Returns 'st'
ordinalize($integer) | Parameters: |
|
|---|---|
| Returns: |
Ordinalized integer |
| Return type: |
string |
Turns a number into an ordinal string used to denote the position such as 1st, 2nd, 3rd, 4th. Example:
ordinalize(1); // Returns '1st'
© 2014–2020 British Columbia Institute of Technology
Licensed under the MIT License.
https://codeigniter.com/user_guide/helpers/inflector_helper.html