Documentation

Text
in package

Table of Contents

Methods

camelCase_to_snake_case()  : string
Convert a string from camelCase to snake_case
isVowel()  : bool
Is this a vowel?
overlap()  : string
What portion of string `$a` and `$b` overlap with each other?
pluralize()  : string
Pluralize a singular word
snake_case_to_PascalCase()  : string
Convert a string from snake_case to PascalCase
titleCase()  : string
Converts $title to Title Case, and returns the result

Methods

camelCase_to_snake_case()

Convert a string from camelCase to snake_case

public static camelCase_to_snake_case(string $camelCase) : string

Word breaks are assumed to be indicated by changes in case, so fooBarBaz will become foo_bar_baz, but fooBARBaz will also become foo_bar_baz

Parameters
$camelCase : string

original string (presumed to be in camelCase -- or PascalCase)

Return values
string

isVowel()

Is this a vowel?

public static isVowel(string $char[, bool $sometimesY = true ]) : bool

The string is processed case-insensitively, and by default y is a vowel. To exclude y pass false as $sometimesY argument. Multi-character strings will never be vowels.

Parameters
$char : string

the string to check (ideally a single character)

$sometimesY : bool = true

(Optional, default is TRUE)

Return values
bool

overlap()

What portion of string `$a` and `$b` overlap with each other?

public static overlap(string $a, string $b[, bool $swap = true ]) : string

For example if $a is 'abcdefg' and $b is 'fgjkli', the overlapping portion would be 'fg'.

Parameters
$a : string
$b : string
$swap : bool = true

Attempt to swap $a and $b to find overlap. (default: true)

Return values
string

Overlapping portion of $a and $b, '' if no overlap

pluralize()

Pluralize a singular word

public static pluralize(string $singular) : string

This uses assumptions based on the English language and its pluralization "rules" (e.g. words end in ch, s, sh, x, and z will be pluralized by adding es rather than s and words ending in a consonant + y will be pluralized by changing the y to ies, as in lazy becomes lazies, while day should become days). The pluralization matches the last character (or character group) that is used to determine the pluralizing suffix (so fisH would become fisHES while FISh would become FIShes).

Parameters
$singular : string
Return values
string

snake_case_to_PascalCase()

Convert a string from snake_case to PascalCase

public static snake_case_to_PascalCase(string $snake_case) : string
Parameters
$snake_case : string

original string (presumed to be in snake_case)

Return values
string

PascalCase version of the string

titleCase()

Converts $title to Title Case, and returns the result

public static titleCase(string $title[, array<string|int, mixed> $params = [] ]) : string
Parameters
$title : string
$params : array<string|int, mixed> = []

An associative array of additional special cases, e.g. (with any subset of the keys below) ``` [ 'lowerCaseWords' => ['foo', 'bar'], 'allCapsWords' => ['BAZ'], 'camelCaseWords' => ['foobarbaz' => 'fooBarBaz'], 'spaceEquivalents' => ['\t'] ]

Tags
see
http://www.sitepoint.com/title-case-in-php/

SitePoint

Return values
string

        
On this page

Search results