Inflector Helper

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

Loading this Helper

This helper is loaded using the following code:

  1. helper('inflector');

Available Functions

The following functions are available:

  • singular($string)

Parameters:

  • $string (string) – Input stringReturns:A singular wordReturn type:string

Changes a plural word to singular. Example:

  1. echo singular('dogs'); // Prints 'dog'
  • plural($string)

Parameters:

  • $string (string) – Input stringReturns:A plural wordReturn type:string

Changes a singular word to plural. Example:

  1. echo plural('dog'); // Prints 'dogs'
  • counted($count, $string)

Parameters:

  • $count (int) – Number of items
  • $string (string) – Input stringReturns:A singular or plural phraseReturn type:string

Changes a word and its count to a phrase. Example:

  1. echo counted(3, 'dog'); // Prints '3 dogs'
  • camelize($string)

Parameters:

  • $string (string) – Input stringReturns:Camel case stringReturn type:string

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

  1. echo camelize('my_dog_spot'); // Prints 'myDogSpot'
  • pascalize($string)

Parameters:

  • $string (string) – Input stringReturns:Pascal case stringReturn type:string

Changes a string of words separated by spaces or underscores to Pascalcase, which is camel case with the first letter capitalized. Example:

  1. echo pascalize('my_dog_spot'); // Prints 'MyDogSpot'
  • underscore($string)

Parameters:

  • $string (string) – Input stringReturns:String containing underscores instead of spacesReturn type:string

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

  1. echo underscore('my dog spot'); // Prints 'my_dog_spot'
  • humanize($string[, $separator = ''_])

Parameters:

  • $string (string) – Input string
  • $separator (string) – Input separatorReturns:Humanized stringReturn type:string

Takes multiple words separated by underscores and adds spaces betweenthem. Each word is capitalized.

Example:

  1. echo humanize('my_dog_spot'); // Prints 'My Dog Spot'

To use dashes instead of underscores:

  1. echo humanize('my-dog-spot', '-'); // Prints 'My Dog Spot'
  • ispluralizable($word_)

Parameters:

  • $word (string) – Input stringReturns:TRUE if the word is countable or FALSE if notReturn type:bool

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

  1. is_pluralizable('equipment'); // Returns FALSE
  • dasherize($string)

Parameters:

  • $string (string) – Input stringReturns:Dasherized stringReturn type:string

Replaces underscores with dashes in the string. Example:

  1. dasherize('hello_world'); // Returns 'hello-world'
  • ordinal($integer)

Parameters:

  • $integer (int) – The integer to determine the suffixReturns:Ordinal suffixReturn type:string

Returns the suffix that should be added to anumber to denote the position such as1st, 2nd, 3rd, 4th. Example:

  1. ordinal(1); // Returns 'st'
  • ordinalize($integer)

Parameters:

  • $integer (int) – The integer to ordinalizeReturns:Ordinalized integerReturn type:string

Turns a number into an ordinal string usedto denote the position such as 1st, 2nd, 3rd, 4th.Example:

  1. ordinalize(1); // Returns '1st'