KaURLify
in component
Transliterates text to ASCII and converts it to URL-friendly strings (SEO keywords). Based on https://github.com/jbroadway/urlify.
Table of Contents
Constants
- URL_FILE = 'file'
- URL_NATIONAL = 'national'
- URL_REGULAR = 'regular'
Properties
Methods
- add_chars() : void
- Adds new characters to the transliteration list.
- downcode() : string
- Transliterates characters to their ASCII equivalents.
- filter() : string
- Converts a string to a URL-friendly form, e.g. "Petty theft" to "petty-theft".
- remove_words() : mixed
- Appends words to the list of words removed by filter().
- transliterate() : string
- Alias of downcode() with default parameters.
- init() : mixed
- Builds the character map and regular expression, giving priority to the map of the specified language.
Constants
URL_FILE
public
mixed
URL_FILE
= 'file'
URL_NATIONAL
public
mixed
URL_NATIONAL
= 'national'
URL_REGULAR
public
mixed
URL_REGULAR
= 'regular'
Properties
$maps
public
static mixed
$maps
= array('de' => array(
/* German */
'Ä' => 'Ae',
'Ö' => 'Oe',
'Ü' => 'Ue',
'ä' => 'ae',
'ö' => 'oe',
'ü' => 'ue',
'ß' => 'ss',
'ẞ' => 'SS',
), 'latin' => array('À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Ă' => 'A', 'Æ' => 'AE', 'Ç' => 'C', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ð' => 'D', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ő' => 'O', 'Ø' => 'O', 'Ș' => 'S', 'Ț' => 'T', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ű' => 'U', 'Ý' => 'Y', 'Þ' => 'TH', 'ß' => 'ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'ă' => 'a', 'æ' => 'ae', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'd', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ő' => 'o', 'ø' => 'o', 'ș' => 's', 'ț' => 't', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'ű' => 'u', 'ý' => 'y', 'þ' => 'th', 'ÿ' => 'y'), 'latin_symbols' => array('©' => '(c)'), 'el' => array(
/* Greek */
'α' => 'a',
'β' => 'b',
'γ' => 'g',
'δ' => 'd',
'ε' => 'e',
'ζ' => 'z',
'η' => 'h',
'θ' => '8',
'ι' => 'i',
'κ' => 'k',
'λ' => 'l',
'μ' => 'm',
'ν' => 'n',
'ξ' => '3',
'ο' => 'o',
'π' => 'p',
'ρ' => 'r',
'σ' => 's',
'τ' => 't',
'υ' => 'y',
'φ' => 'f',
'χ' => 'x',
'ψ' => 'ps',
'ω' => 'w',
'ά' => 'a',
'έ' => 'e',
'ί' => 'i',
'ό' => 'o',
'ύ' => 'y',
'ή' => 'h',
'ώ' => 'w',
'ς' => 's',
'ϊ' => 'i',
'ΰ' => 'y',
'ϋ' => 'y',
'ΐ' => 'i',
'Α' => 'A',
'Β' => 'B',
'Γ' => 'G',
'Δ' => 'D',
'Ε' => 'E',
'Ζ' => 'Z',
'Η' => 'H',
'Θ' => '8',
'Ι' => 'I',
'Κ' => 'K',
'Λ' => 'L',
'Μ' => 'M',
'Ν' => 'N',
'Ξ' => '3',
'Ο' => 'O',
'Π' => 'P',
'Ρ' => 'R',
'Σ' => 'S',
'Τ' => 'T',
'Υ' => 'Y',
'Φ' => 'F',
'Χ' => 'X',
'Ψ' => 'PS',
'Ω' => 'W',
'Ά' => 'A',
'Έ' => 'E',
'Ί' => 'I',
'Ό' => 'O',
'Ύ' => 'Y',
'Ή' => 'H',
'Ώ' => 'W',
'Ϊ' => 'I',
'Ϋ' => 'Y',
), 'tr' => array(
/* Turkish */
'ş' => 's',
'Ş' => 'S',
'ı' => 'i',
'İ' => 'I',
'ç' => 'c',
'Ç' => 'C',
'ü' => 'u',
'Ü' => 'U',
'ö' => 'o',
'Ö' => 'O',
'ğ' => 'g',
'Ğ' => 'G',
), 'ru' => array(
/* Russian */
'а' => 'a',
'б' => 'b',
'в' => 'v',
'г' => 'g',
'д' => 'd',
'е' => 'e',
'ё' => 'yo',
'ж' => 'zh',
'з' => 'z',
'и' => 'i',
'й' => 'j',
'к' => 'k',
'л' => 'l',
'м' => 'm',
'н' => 'n',
'о' => 'o',
'п' => 'p',
'р' => 'r',
'с' => 's',
'т' => 't',
'у' => 'u',
'ф' => 'f',
'х' => 'h',
'ц' => 'c',
'ч' => 'ch',
'ш' => 'sh',
'щ' => 'sh',
'ъ' => '',
'ы' => 'y',
'ь' => '',
'э' => 'e',
'ю' => 'yu',
'я' => 'ya',
'А' => 'A',
'Б' => 'B',
'В' => 'V',
'Г' => 'G',
'Д' => 'D',
'Е' => 'E',
'Ё' => 'Yo',
'Ж' => 'Zh',
'З' => 'Z',
'И' => 'I',
'Й' => 'J',
'К' => 'K',
'Л' => 'L',
'М' => 'M',
'Н' => 'N',
'О' => 'O',
'П' => 'P',
'Р' => 'R',
'С' => 'S',
'Т' => 'T',
'У' => 'U',
'Ф' => 'F',
'Х' => 'H',
'Ц' => 'C',
'Ч' => 'Ch',
'Ш' => 'Sh',
'Щ' => 'Sh',
'Ъ' => '',
'Ы' => 'Y',
'Ь' => '',
'Э' => 'E',
'Ю' => 'Yu',
'Я' => 'Ya',
'№' => '',
), 'uk' => array(
/* Ukrainian */
'Є' => 'Ye',
'І' => 'I',
'Ї' => 'Yi',
'Ґ' => 'G',
'є' => 'ye',
'і' => 'i',
'ї' => 'yi',
'ґ' => 'g',
), 'cs' => array(
/* Czech */
'č' => 'c',
'ď' => 'd',
'ě' => 'e',
'ň' => 'n',
'ř' => 'r',
'š' => 's',
'ť' => 't',
'ů' => 'u',
'ž' => 'z',
'Č' => 'C',
'Ď' => 'D',
'Ě' => 'E',
'Ň' => 'N',
'Ř' => 'R',
'Š' => 'S',
'Ť' => 'T',
'Ů' => 'U',
'Ž' => 'Z',
), 'pl' => array(
/* Polish */
'ą' => 'a',
'ć' => 'c',
'ę' => 'e',
'ł' => 'l',
'ń' => 'n',
'ó' => 'o',
'ś' => 's',
'ź' => 'z',
'ż' => 'z',
'Ą' => 'A',
'Ć' => 'C',
'Ę' => 'e',
'Ł' => 'L',
'Ń' => 'N',
'Ó' => 'O',
'Ś' => 'S',
'Ź' => 'Z',
'Ż' => 'Z',
), 'ro' => array(
/* Romanian */
'ă' => 'a',
'â' => 'a',
'î' => 'i',
'ș' => 's',
'ț' => 't',
'Ţ' => 'T',
'ţ' => 't',
), 'lv' => array(
/* Latvian */
'ā' => 'a',
'č' => 'c',
'ē' => 'e',
'ģ' => 'g',
'ī' => 'i',
'ķ' => 'k',
'ļ' => 'l',
'ņ' => 'n',
'š' => 's',
'ū' => 'u',
'ž' => 'z',
'Ā' => 'A',
'Č' => 'C',
'Ē' => 'E',
'Ģ' => 'G',
'Ī' => 'i',
'Ķ' => 'k',
'Ļ' => 'L',
'Ņ' => 'N',
'Š' => 'S',
'Ū' => 'u',
'Ž' => 'Z',
), 'lt' => array(
/* Lithuanian */
'ą' => 'a',
'č' => 'c',
'ę' => 'e',
'ė' => 'e',
'į' => 'i',
'š' => 's',
'ų' => 'u',
'ū' => 'u',
'ž' => 'z',
'Ą' => 'A',
'Č' => 'C',
'Ę' => 'E',
'Ė' => 'E',
'Į' => 'I',
'Š' => 'S',
'Ų' => 'U',
'Ū' => 'U',
'Ž' => 'Z',
), 'vn' => array(
/* Vietnamese */
'Á' => 'A',
'À' => 'A',
'Ả' => 'A',
'Ã' => 'A',
'Ạ' => 'A',
'Ă' => 'A',
'Ắ' => 'A',
'Ằ' => 'A',
'Ẳ' => 'A',
'Ẵ' => 'A',
'Ặ' => 'A',
'Â' => 'A',
'Ấ' => 'A',
'Ầ' => 'A',
'Ẩ' => 'A',
'Ẫ' => 'A',
'Ậ' => 'A',
'á' => 'a',
'à' => 'a',
'ả' => 'a',
'ã' => 'a',
'ạ' => 'a',
'ă' => 'a',
'ắ' => 'a',
'ằ' => 'a',
'ẳ' => 'a',
'ẵ' => 'a',
'ặ' => 'a',
'â' => 'a',
'ấ' => 'a',
'ầ' => 'a',
'ẩ' => 'a',
'ẫ' => 'a',
'ậ' => 'a',
'É' => 'E',
'È' => 'E',
'Ẻ' => 'E',
'Ẽ' => 'E',
'Ẹ' => 'E',
'Ê' => 'E',
'Ế' => 'E',
'Ề' => 'E',
'Ể' => 'E',
'Ễ' => 'E',
'Ệ' => 'E',
'é' => 'e',
'è' => 'e',
'ẻ' => 'e',
'ẽ' => 'e',
'ẹ' => 'e',
'ê' => 'e',
'ế' => 'e',
'ề' => 'e',
'ể' => 'e',
'ễ' => 'e',
'ệ' => 'e',
'Í' => 'I',
'Ì' => 'I',
'Ỉ' => 'I',
'Ĩ' => 'I',
'Ị' => 'I',
'í' => 'i',
'ì' => 'i',
'ỉ' => 'i',
'ĩ' => 'i',
'ị' => 'i',
'Ó' => 'O',
'Ò' => 'O',
'Ỏ' => 'O',
'Õ' => 'O',
'Ọ' => 'O',
'Ô' => 'O',
'Ố' => 'O',
'Ồ' => 'O',
'Ổ' => 'O',
'Ỗ' => 'O',
'Ộ' => 'O',
'Ơ' => 'O',
'Ớ' => 'O',
'Ờ' => 'O',
'Ở' => 'O',
'Ỡ' => 'O',
'Ợ' => 'O',
'ó' => 'o',
'ò' => 'o',
'ỏ' => 'o',
'õ' => 'o',
'ọ' => 'o',
'ô' => 'o',
'ố' => 'o',
'ồ' => 'o',
'ổ' => 'o',
'ỗ' => 'o',
'ộ' => 'o',
'ơ' => 'o',
'ớ' => 'o',
'ờ' => 'o',
'ở' => 'o',
'ỡ' => 'o',
'ợ' => 'o',
'Ú' => 'U',
'Ù' => 'U',
'Ủ' => 'U',
'Ũ' => 'U',
'Ụ' => 'U',
'Ư' => 'U',
'Ứ' => 'U',
'Ừ' => 'U',
'Ử' => 'U',
'Ữ' => 'U',
'Ự' => 'U',
'ú' => 'u',
'ù' => 'u',
'ủ' => 'u',
'ũ' => 'u',
'ụ' => 'u',
'ư' => 'u',
'ứ' => 'u',
'ừ' => 'u',
'ử' => 'u',
'ữ' => 'u',
'ự' => 'u',
'Ý' => 'Y',
'Ỳ' => 'Y',
'Ỷ' => 'Y',
'Ỹ' => 'Y',
'Ỵ' => 'Y',
'ý' => 'y',
'ỳ' => 'y',
'ỷ' => 'y',
'ỹ' => 'y',
'ỵ' => 'y',
'Đ' => 'D',
'đ' => 'd',
), 'ar' => array(
/* Arabic */
'أ' => 'a',
'ب' => 'b',
'ت' => 't',
'ث' => 'th',
'ج' => 'g',
'ح' => 'h',
'خ' => 'kh',
'د' => 'd',
'ذ' => 'th',
'ر' => 'r',
'ز' => 'z',
'س' => 's',
'ش' => 'sh',
'ص' => 's',
'ض' => 'd',
'ط' => 't',
'ظ' => 'th',
'ع' => 'aa',
'غ' => 'gh',
'ف' => 'f',
'ق' => 'k',
'ك' => 'k',
'ل' => 'l',
'م' => 'm',
'ن' => 'n',
'ه' => 'h',
'و' => 'o',
'ي' => 'y',
), 'sr' => array(
/* Serbian */
'ђ' => 'dj',
'ј' => 'j',
'љ' => 'lj',
'њ' => 'nj',
'ћ' => 'c',
'џ' => 'dz',
'đ' => 'dj',
'Ђ' => 'Dj',
'Ј' => 'j',
'Љ' => 'Lj',
'Њ' => 'Nj',
'Ћ' => 'C',
'Џ' => 'Dz',
'Đ' => 'Dj',
), 'az' => array(
/* Azerbaijani */
'ç' => 'c',
'ə' => 'e',
'ğ' => 'g',
'ı' => 'i',
'ö' => 'o',
'ş' => 's',
'ü' => 'u',
'Ç' => 'C',
'Ə' => 'E',
'Ğ' => 'G',
'İ' => 'I',
'Ö' => 'O',
'Ş' => 'S',
'Ü' => 'U',
))
$remove_list
List of words to remove from URLs.
public
static mixed
$remove_list
= array()
$chars
The character list as a string.
protected
static mixed
$chars
= ''
$language
The current language
protected
static mixed
$language
= ''
$map
The character map.
protected
static mixed
$map
= array()
$regex
The character list as a regular expression.
protected
static mixed
$regex
= ''
Methods
add_chars()
Adds new characters to the transliteration list.
public
static add_chars(mixed $map) : void
$map — associative array of character => replacement.
Parameters
- $map : mixed
Tags
downcode()
Transliterates characters to their ASCII equivalents.
public
static downcode(mixed $text[, mixed $language = "" ][, mixed $is_national = false ]) : string
$text — source text. $language — language whose rules have priority. $is_national — keep the characters of the specified language.
Parameters
- $text : mixed
- $language : mixed = ""
- $is_national : mixed = false
Return values
string —Transliterated text.
filter()
Converts a string to a URL-friendly form, e.g. "Petty theft" to "petty-theft".
public
static filter(mixed $text[, mixed $length = 90 ][, mixed $language = "" ][, mixed $url_type = 'regular' ]) : string
$text — source text. $length — maximum length of the result. $language — language whose rules have priority. $url_type — result type: 'regular' (ASCII only), 'file' (dots allowed) or 'national' (national characters kept).
Parameters
- $text : mixed
- $length : mixed = 90
- $language : mixed = ""
- $url_type : mixed = 'regular'
Return values
string —Filtered lowercase string.
remove_words()
Appends words to the list of words removed by filter().
public
static remove_words(mixed $words) : mixed
$words — word or array of words.
Parameters
- $words : mixed
transliterate()
Alias of downcode() with default parameters.
public
static transliterate(mixed $text) : string
$text — source text.
Parameters
- $text : mixed
Return values
string —Transliterated text.
init()
Builds the character map and regular expression, giving priority to the map of the specified language.
protected
static init([mixed $language = "" ][, mixed $is_national = false ]) : mixed
$language — language code whose map takes priority. $is_national — keep the characters of the language map unchanged.
Parameters
- $language : mixed = ""
- $is_national : mixed = false