Welcome to FrostSW!

FrostMVC PHP Framework

Documentation   |   Version

Words

FrostMVC\Words

use FrostMVC\Words;

String manipulation utilities for pluralisation, URL slugs, and identifier sanitisation.

Methods

::objectify()

Converts a string to a safe PHP identifier using snake_case. Only lowercase ASCII letters, digits, and underscores are retained; all other characters are replaced with '_' when $snake_casing is true, or discarded when it is false. The result is truncated to $length characters.

::pluralise()

Appends the correct plural suffix to a word based on a count. Handles words ending in 's' (unchanged), 'o' (adds 's' or 'es'), 'y' (replaces with 'ies'), and all other endings (adds 's').

::slugify()

Converts a string to a URL-safe slug. The result contains only lowercase alphanumeric characters and hyphens. Spaces become hyphens. Characters not in the allowed set are discarded. Trailing hyphens are trimmed. The output is capped at $maxlength characters.

objectify() static

Words::objectify($string, $snake_casing = true, $length = 128)

Converts a string to a safe PHP identifier using snake_case. Only lowercase ASCII letters, digits, and underscores are retained; all other characters are replaced with '_' when $snake_casing is true, or discarded when it is false. The result is truncated to $length characters.

Parameters

$string string

The input string.

$snake_casing bool

When true, unsupported characters become '_'.

Default: true
$length int

Maximum length. 0 disables truncation.

Default: 128

Returns

string

pluralise() static

Words::pluralise($num, $word, $oes = false)

Appends the correct plural suffix to a word based on a count. Handles words ending in 's' (unchanged), 'o' (adds 's' or 'es'), 'y' (replaces with 'ies'), and all other endings (adds 's').

Parameters

$num int

The quantity.

$word string

The singular form of the word.

$oes bool

When true, words ending in 'o' get 'es' instead of 's'.

Default: false

Returns

string "$num $word[s]" with appropriate pluralisation.

slugify() static

Words::slugify($words, $maxlength = 128)

Converts a string to a URL-safe slug. The result contains only lowercase alphanumeric characters and hyphens. Spaces become hyphens. Characters not in the allowed set are discarded. Trailing hyphens are trimmed. The output is capped at $maxlength characters.

Parameters

$words string

The input string.

$maxlength int

Maximum slug length. Defaults to 128.

Default: 128

Returns

string

Generated from core/classes/Words.php (FrostMVC ).