at 0xb3f7684>
CodeIgniter

3.0-dev User Guide

Inflector Helper

The Inflector Helper file contains functions that permits you to change words to plural, singular, camel case, etc.

Loading this Helper

This helper is loaded using the following code:

$this->load->helper('inflector');

The following functions are available:

singular()

singular($str)
Parameters:
  • $str (string) – Input string
Returns:

string

Changes a plural word to singular. Example:

echo singular('dogs'); // Prints 'dog'

plural()

plural($str)
Parameters:
  • $str (string) – Input string
Returns:

string

Changes a singular word to plural. Example:

echo plural('dog'); // Prints 'dogs'

camelize()

camelize($str)
Parameters:
  • $str (string) – Input string
Returns:

string

Changes a string of words separated by spaces or underscores to camel case. Example:

echo camelize('my_dog_spot'); // Prints 'myDogSpot'

underscore()

camelize($str)
Parameters:
  • $str (string) – Input string
Returns:

string

Takes multiple words separated by spaces and underscores them. Example:

echo underscore('my dog spot'); // Prints 'my_dog_spot'

humanize()

camelize($str)
Parameters:
  • $str (string) – Input string
  • $separator (string) – Input separator
Returns:

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()

is_countable($word)
Parameters:
  • $word (string) – Input string
Returns:

bool

Checks if the given word has a plural version. Example:

is_countable('equipment'); // Returns FALSE