final class Slugger (View source)

Generates best-effort ASCII slugs for use in URLs.

Inspired by the former URLify utility and its curated transliteration maps, this is not a universal Unicode transliterator. Unknown or unsupported characters are discarded, so an unsupported input can produce an empty slug.

Constants

DEFAULT_LOCALE

Default locale used to select the preferred transliteration map.

private SUPPORTED_LOCALES

private MAPS

Internal fallback and language maps copied from the former URLify utility.

Methods

string
slug(string $text, int $maxLength = 120, string $locale = self::DEFAULT_LOCALE)

Converts text into a lowercase ASCII URL slug.

string
array

Returns explicit language locale maps available to applications.

array

Details

slug

string slug(string $text, int $maxLength = 120, string $locale = self::DEFAULT_LOCALE)

Converts text into a lowercase ASCII URL slug.

Parameters

string $text

Input text to normalize.

int $maxLength

Maximum output length; zero or a negative value returns an empty string.

string $locale

Preferred transliteration map.

Return Value

string

A slug containing only lowercase a-z, 0-9 and hyphens, without edge or repeated hyphens. It can be empty when the input contains no supported characters.

supportedLocales

array supportedLocales()

Returns explicit language locale maps available to applications.

Internal fallback maps such as latin and latin_symbols are excluded.

Return Value

array