-
-
Save corleonis/3308218 to your computer and use it in GitHub Desktop.
[php] Филтрирање на стринг за seo friendly url-а
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function seo_friendly_url($url) { | |
$cyrillic = array("а", "б", "в", "г", "д", "ѓ", "е", "ж", "з", "ѕ", "и", "ј", "к", | |
"л", "љ", "м", "н", "њ", "о", "п", "р", "с", "т", "ќ", "у", "ф", | |
"х", "ц", "ч", "џ", "ш", "А", "Б", "В", "Г", "Д", "Ѓ", "Е", "Ж", | |
"З", "Ѕ", "И", "Ј", "К", "Л", "Љ", "М", "Н", "Њ", "О", "П", "Р", | |
"С", "Т", "Ќ", "У", "Ф", "Х", "Ц", "Ч", "Џ", "Ш"); | |
$latin = array("a", "b", "v", "g", "d", "gj", "e", "z", "z", "dz", "i", "j", "k", | |
"l", "lj", "m", "n", "nj", "o", "p", "r", "s", "t", "kj", "u", "f", | |
"h", "c", "ch", "dj", "sh", "A", "B", "V", "G", "D", "Gj", "E", "Z", | |
"Z", "Dz", "I", "J", "K", "L", "Lj", "M", "N", "Nj", "O", "P", "R", | |
"S", "T", "Kj", "U", "F", "H", "C", "Ch", "Dj", "Sh"); | |
$url = str_replace($cyrillic, $latin, $url); | |
$url = strtolower($url); | |
$url = preg_replace('/[^a-zA-Z0-9\-_\s]/', '', $url); | |
$url = str_replace(array(' ', '_'), '-', $url); | |
if (strpos($url, '--') != false) { | |
$url = preg_replace('/\-{2,}/', '-', $url); | |
} | |
if ($url[strlen($url)-1] == '-') { | |
$url[strlen($url)-1] = ''; | |
} | |
return $url; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment