CodeIgniter – Inflector Helper

As I mentioned earlier about CodeIgniter helpers, I would like to explain about “Inflector Helper”.

This helper would be useful for working with String. When you have a string as “he_is_a_good_boy”. We can change it as a readable string with spaces in between words instead of underscore. We can do it by using PHP function “str_replace”.

The another easy way of doing it using CodeIgniter is by using this helper.


Consider the example,

$word = "he_is_a_good_boy";
echo humanize($word); // Returns "He Is A Good Boy"

We can also reverse the process. Consider the following example

$word = "He Is A Good Boy";
echo underscore($word); // Returns "he_is_a_good_boy"

When you have a word and you have to replace it with the plural or singular of that word. This operation is made easy in CodeIgniter.

$word = "dogs";
echo singular($word); // Returns "dog"

$word = "dog";
echo plural($word); // Returns "dogs"

And in some cases, you may have to use camel case. ex. maxNumber. This can also be obtained by

$word = "my_max_num";
echo camelize($word); // Returns "myMaxNum"

Helpers makes are task easier. So we have to use them to reduce the amount of time involved and to reduce the number of lines in our code. It also makes the code efficient.

Thanks for reading.

Follow me


Web Developer at Energy Alternatives India
I'm interested in developing Web applications andkeen on learning new technologies.

View Nagarajan's Profile
Follow me

Latest posts by Nagarajan (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *

займ на карту онлайн круглосуточно