Codeigniter Inflector Helper
Codeigniter Inflector Helper – Codeigniter inflector helper provide various functions that are used to convert english word to inflector case. $this->load->helper(‘inflector’);is used to load the helper. This contains functions that permit you to change english words to plural, singular, camel case etc. Here in this tutorial, we are going to explain how to this helper with the example.
Codeigniter inflector helper example
Now we will see how to load inflector helper in codeigniter and then use its function-
Load email helper
$this->load->helper('Inflector'); |
Functions:-
Following functions are available in inflector helper.
- 1. Singular Function
- 2. Plural Function
- 3. Camelize Function
- 4. Underscore Function
- 5. Humanize Function
- 6. is_countable Function
1. Singular function
Singular function is used to change a plural word to singular
Syntax of singular function is :-
singular($str) |
- $str (string) : Input string
- Returns : A singular word
- Return type : string
Parameters:
EXAMPLE
Here is simple example of inflector tags.
Inflector function tags in codeigniter example:-
//Controllers part public function inflect() { $this->load->helper('Inflector '); $this->load->view('view_page'); } // Views parts <h3>plural to singular</h3> <?php echo singular('Dogs');?><br> <?php echo singular('Lions');?><br> <?php echo singular('Tigers');?><br> <?php echo singular('Elephants');?><br> <?php echo singular('Goats');?><br> |
The output of the above example will be something like this –
2. Plural function
Plural function is used to change a singular word to plural
Syntax of plural function is :-
plural($str) |
- $str (string) : Input string
- Returns : A plural word
- Return type : string
Parameters:
EXAMPLE
Here is simple example of plural inflector tags.
Plural inflector function tags in codeigniter example:-
// Views parts <h3>Singular to Plural </h3> <?php echo singular('Apple');?><br> <?php echo singular('Orange');?><br> <?php echo singular('Mango');?><br> <?php echo singular('PineApple');?> |
The output of the above example will be something like this –
3. Camelized function
Camelized function is used to change a words separated by spaces or underscores to camel case
Syntax of camelized function is :-
camelize($str) |
- $str (string) : Input string
- Returns : Camelized string
- Return type : string
Parameters:
EXAMPLE
Here is simple example of camelized inflector tags.
Camelized inflector function tags in codeigniter example:-
// Views parts <h3>Camelized function</h3> <?php echo camelize('www._tutorials plane._com');?><br> <?php echo camelize('www___.solidcoupon._ com');?> |
The output of the above example will be something like this –
4. UnderScore function
Underscore function is used to take multiple words separated by spaces and underscores them
Syntax of underscore function is :-
underscore($str) |
- $str (string) : Input string
- Returns : String containing underscores instead of spaces
- Return type : string
Parameters:
EXAMPLE
Here is simple example of underscore inflector Tags.
Underscore inflector function tags in codeigniter example:-
// Views parts <h3>UnderScore function</h3> <?php echo underscore('Welcome To Tutorials plane');?><br> <?php echo underscore('Welcome To Solid Coupon');?><br> <?php echo underscore('my dog spot');?><br> |
The output of the above example will be something like this –
5. Humanized function
Humanized function is used to take multiple words separated by underscores and adds spaces between them. Each word is capitalized
Syntax of humanized function is :-
humanize($str[$separator = '_']) |
- $str (string) : Input string
- $separator (string) : Input separator
- Returns : Humanized string
- Return type : string
Parameters:
EXAMPLE
Here is simple example of humanized inflector tags.
Humanized inflector function tags in codeigniter example:-
// Views parts <h3>Humanized function</h3> <?php echo underscore('Welcome To Tutorials plane');?><br> <?php echo underscore('Welcome To Solid Coupon');?><br> <?php echo underscore('my dog spot');?><br> |
The output of the above example will be something like this –
6. Countable function
Countable function is used to print output in boolean data type
Syntax of countable function is :-
is_countable($word) |
- $word (string) : Input string
- Returns : TRUE if the word is countable or FALSE if not
- Return type : bool
Parameters:
EXAMPLE
Here is simple example of countable inflector tags.
Countable inflector function tags in codeigniter example:-
// Views parts <h3>Countable function</h3> <?php $check = is_countable('books'); if($check) { echo true; } else { echo false; } ?> |
The output of the above example will be something like this –
Advertisements