lithium\util\Inflector::slug()

public static method

Returns a string with all spaces converted to given replacement and non word characters removed. Maps special characters to ASCII using Inflector::$_transliteration, which can be updated using Inflector::rules().

Parameters

  • string $string

    An arbitrary string to convert.

  • string $replacement

    The replacement to use for spaces.

Returns

string

The converted string.

Source

	public static function slug($string, $replacement = '-') {
		$map = static::$_transliteration + [
			'/[^\s\p{L}\p{Nd}]/u' => ' ',
			'/\s+/u' => $replacement,
			'/(?<=[a-z])([A-Z])/' => $replacement . '\\1',
			str_replace(':rep', preg_quote($replacement, '/'), '/^[:rep]+|[:rep]+$/') => ''
		];
		return preg_replace(array_keys($map), array_values($map), $string);
	}