CodeIgniter Inflector Helper

Facebooktwitterredditpinterestlinkedinmailby feather

The inflector helper file contains some predefined function that allows users to change their English words into plural, singular, and camel case, etc.

Loading an Inflector Helper

Before using an inflector helper function, you must load the helper in the controller’s files.

Syntax

Functions of an Inflector helper:

1`. singular(): It converts plural words into singular words. For example, boys converts into boy, girls converts into girl, etc.

syntax

$str: It takes an input string to define a singular function.

Example

2. plural(): It converts singular word into plural. For example, boy converts into boys, girl converts into girls, etc.

syntax

$str: It takes an input string to define a plural function.

Example

3. camelize(): It converts a compound string to the camel case format. It removes spaces and underscores between words.

Syntax

$str: It takes a string, as input.

Example

4. underscore(): It converts multiple words into an underscore format. It removes spaces among the words.

Syntax

$str: It takes a string, as an input.

Example

5. humanize(): It converts a string into a human-readable format by removing underscores. It adds spaces among the words.

Syntax

$str: It defines a string.

$seperator : It defines an input separator such as ‘-‘ that extracts all hyphens from the input string and creates the string in a human-readable form.

Example

6. word_is_countable(): It returns a boolean value, if the given input string is countable or not.

Syntax

$word: It takes a word as an input.

Example

Create a simple program of an Inflector helper

Create a controller file in application/controller named Online.php. In this file write the following program:

Online.php

When you execute the above program in localhost by invoking the URL localhost/CodeIgniter-3.1.11/index.php/Online/, it shows the output, as shown below.

CodeIgniter Inflector Helper
Facebooktwitterredditpinterestlinkedinmailby feather