Inflector Helper

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

Loading this Helper

This helper is loaded using the following code:

helper('inflector');

Available Functions

The following functions are available:

singular($string)
パラメータ:
  • $string (string) -- Input string
戻り値:

A singular word

戻り値の型:

string

Changes a plural word to singular. 例:

echo singular('dogs'); // Prints 'dog'
plural($string)
パラメータ:
  • $string (string) -- Input string
戻り値:

A plural word

戻り値の型:

string

Changes a singular word to plural. 例:

echo plural('dog'); // Prints 'dogs'
camelize($string)
パラメータ:
  • $string (string) -- Input string
戻り値:

Camelized string

戻り値の型:

string

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

echo camelize('my_dog_spot'); // Prints 'myDogSpot'
underscore($string)
パラメータ:
  • $string (string) -- Input string
戻り値:

String containing underscores instead of spaces

戻り値の型:

string

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

echo underscore('my dog spot'); // Prints 'my_dog_spot'
humanize($string[, $separator = '_'])
パラメータ:
  • $string (string) -- Input string
  • $separator (string) -- Input separator
戻り値:

Humanized string

戻り値の型:

string

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

例:

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_pluralizable($word)
パラメータ:
  • $word (string) -- Input string
戻り値:

TRUE if the word is countable or FALSE if not

戻り値の型:

bool

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

is_pluralizable('equipment'); // Returns FALSE
dasherize($string)
パラメータ:
  • $string (string) -- Input string
戻り値:

Dasherized string

戻り値の型:

string

Replaces underscores with dashes in the string. 例:

dasherize('hello_world'); // Returns 'hello-world'
ordinal($integer)
パラメータ:
  • $integer (int) -- The integer to determine the suffix
戻り値:

Ordinal suffix

戻り値の型:

string

Returns the suffix that should be added to a number to denote the position such as 1st, 2nd, 3rd, 4th. 例:

ordinal(1); // Returns 'st'
ordinalize($integer)
パラメータ:
  • $integer (int) -- The integer to ordinalize
戻り値:

Ordinalized integer

戻り値の型:

string

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

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