Skip to content

Instantly share code, notes, and snippets.

@corleonis
Forked from angelov/seo_friendly_url.php
Created July 20, 2012 13:58
Show Gist options
  • Save corleonis/3150867 to your computer and use it in GitHub Desktop.
Save corleonis/3150867 to your computer and use it in GitHub Desktop.
[php] Филтрирање на стринг за seo friendly url-а
<?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