HumHub Documentation (unofficial)

URLify
in package

A fast PHP slug generator and transliteration library, started as a PHP port of URLify.js from the Django project + fallback via "Portable ASCII".

  • https://github.com/django/django/blob/master/django/contrib/admin/static/admin/js/urlify.js
  • https://github.com/voku/portable-ascii

Handles symbols from latin languages, Arabic, Azerbaijani, Bulgarian, Burmese, Croatian, Czech, Danish, Esperanto, Estonian, Finnish, French, Switzerland (French), Austrian (French), Georgian, German, Switzerland (German), Austrian (German), Greek, Hindi, Kazakh, Latvian, Lithuanian, Norwegian, Persian, Polish, Romanian, Russian, Swedish, Serbian, Slovak, Turkish, Ukrainian and Vietnamese ... and many other via "ASCII::to_transliterate()".

Table of Contents

Properties

$maps  : array<string|int, array<string|int, mixed>>
The language-mapping array.
$remove_list  : array<string|int, array<string|int, mixed>>
List of words to remove from URLs.
$arrayToSeparator  : array<string|int, string>
An array of strings that will convert into the separator-char - used by "URLify::filter()".

Methods

add_array_to_separator()  : void
Add new strings the will be replaced with the separator.
add_chars()  : void
Add new characters to the list. `$map` should be a hash.
downcode()  : string
Transliterates characters to their ASCII equivalents.
filter()  : string
Convert a String to URL.
remove_words()  : void
Append words to the remove list. Accepts either single words or an array of words.
reset_array_to_separator()  : void
Reset the internal "self::$arrayToSeparator" to the default values.
reset_chars()  : void
reset_remove_list()  : void
reset the word-remove-array
slug()  : string
Convert a String to URL slug. Wraps <strong>filter()</strong> with a simpler set of defaults for typical usage in generating blog post slugs.
transliterate()  : string
Alias of `URLify::downcode()`.
expandString()  : string
Expands the given string replacing some special parts for words.
expandCurrencies()  : string
Expands the numeric currencies in euros, dollars, pounds and yens that the given string may include.
expandSymbols()  : string
Expands the special symbols that the given string may include, such as '@', '.', '#' and '%'.
get_language_for_reset_remove_list()  : string
get_remove_list()  : array<string|int, mixed>
return the "self::$remove_list[$language]" array

Properties

$maps

The language-mapping array.

public static array<string|int, array<string|int, mixed>> $maps = []

ISO 639-1 codes: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

$remove_list

List of words to remove from URLs.

public static array<string|int, array<string|int, mixed>> $remove_list = []

$arrayToSeparator

An array of strings that will convert into the separator-char - used by "URLify::filter()".

private static array<string|int, string> $arrayToSeparator = []

Methods

add_array_to_separator()

Add new strings the will be replaced with the separator.

public static add_array_to_separator(array<string|int, mixed> $array[, bool $merge = true ]) : void
Parameters
$array : array<string|int, mixed>

An array of things that should replaced by the separator.

$merge : bool = true

Keep the previous (default) array-to-separator array.

Tags
psalm-param

string[] $array

add_chars()

Add new characters to the list. `$map` should be a hash.

public static add_chars(array<string|int, mixed> $map[, string|null $language = null ]) : void
Parameters
$map : array<string|int, mixed>
$language : string|null = null
Tags
psalm-param

array<string, string> $map

downcode()

Transliterates characters to their ASCII equivalents.

public static downcode(string $string[, string $language = 'en' ][, string $unknown = '' ]) : string

$language specifies a priority for a specific language. The latter is useful if languages have different rules for the same character.

Parameters
$string : string

The input string.

$language : string = 'en'

Your primary language.

$unknown : string = ''

Character use if character unknown. (default is ?).

Return values
string

filter()

Convert a String to URL.

public static filter(string $string[, int $maxLength = 200 ][, string $language = 'en' ][, bool $fileName = false ][, bool $removeWords = false ][, bool $strToLower = true ][, bool|string $separator = '-' ]) : string

e.g.: "Petty
theft" to "Petty-theft"

Parameters
$string : string

The text you want to convert.

$maxLength : int = 200

Max. length of the output string, set to "0" (zero) to disable it

$language : string = 'en'

The language you want to convert to.

$fileName : bool = false

Keep the "." from the extension e.g.: "imaäe.jpg" => "image.jpg"

$removeWords : bool = false

Remove some "words" from the string.
Info: Set extra words via remove_words().

$strToLower : bool = true

Use strtolower() at the end.

$separator : bool|string = '-'

Define a new separator for the words.

Return values
string

remove_words()

Append words to the remove list. Accepts either single words or an array of words.

public static remove_words(string|array<string|int, string> $words[, string $language = 'en' ][, bool $merge = true ]) : void
Parameters
$words : string|array<string|int, string>
$language : string = 'en'
$merge : bool = true

Keep the previous (default) remove-words array.

reset_array_to_separator()

Reset the internal "self::$arrayToSeparator" to the default values.

public static reset_array_to_separator() : void

reset_chars()

public static reset_chars() : void

reset_remove_list()

reset the word-remove-array

public static reset_remove_list([string $language = 'en' ]) : void
Parameters
$language : string = 'en'

slug()

Convert a String to URL slug. Wraps <strong>filter()</strong> with a simpler set of defaults for typical usage in generating blog post slugs.

public static slug(string $string[, int $maxLength = 200 ][, string $separator = '-' ][, string $language = 'en' ]) : string
Parameters
$string : string

The text you want to convert.

$maxLength : int = 200

Max. length of the output string, set to "0" (zero) to disable it

$separator : string = '-'

Define a new separator for the words.

$language : string = 'en'

The language you want to convert to.

Return values
string

transliterate()

Alias of `URLify::downcode()`.

public static transliterate(string $string[, string $language = 'en' ]) : string
Parameters
$string : string
$language : string = 'en'
Return values
string

expandString()

Expands the given string replacing some special parts for words.

protected static expandString(string $string[, string $language = 'en' ]) : string

e.g. "lorem@ipsum.com" is replaced by "lorem at ipsum dot com".

Most of these transformations have been inspired by the pelle/slugger project, distributed under the Eclipse Public License. Copyright 2012 Pelle Braendgaard

Parameters
$string : string

The string to expand

$language : string = 'en'
Return values
string

The result of expanding the string

expandCurrencies()

Expands the numeric currencies in euros, dollars, pounds and yens that the given string may include.

private static expandCurrencies(string $string[, string $language = 'en' ]) : string
Parameters
$string : string
$language : string = 'en'
Return values
string

expandSymbols()

Expands the special symbols that the given string may include, such as '@', '.', '#' and '%'.

private static expandSymbols(string $string[, string $language = 'en' ]) : string
Parameters
$string : string
$language : string = 'en'
Return values
string

get_language_for_reset_remove_list()

private static get_language_for_reset_remove_list(string $language) : string
Parameters
$language : string
Return values
string

get_remove_list()

return the "self::$remove_list[$language]" array

private static get_remove_list([string $language = 'en' ]) : array<string|int, mixed>
Parameters
$language : string = 'en'
Return values
array<string|int, mixed>

        
On this page

Search results