Created
August 6, 2013 16:27
-
-
Save kovaldn/6166105 to your computer and use it in GitHub Desktop.
PHP: slug (translate string from rus to eng)
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 sozdat_slag($stroka) { | |
$rus=array('А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я','а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я',' '); | |
$lat=array('a','b','v','g','d','e','e','gh','z','i','y','k','l','m','n','o','p','r','s','t','u','f','h','c','ch','sh','sch','y','y','y','e','yu','ya','a','b','v','g','d','e','e','gh','z','i','y','k','l','m','n','o','p','r','s','t','u','f','h','c','ch','sh','sch','y','y','y','e','yu','ya',' '); | |
$stroka = str_replace($rus, $lat, $stroka); // перевеодим на английский | |
$stroka = str_replace('-', '', $stroka); // удаляем все исходные "-" | |
$slag = preg_replace('/[^A-Za-z0-9-]+/', '-', $stroka); // заменяет все символы и пробелы на "-" | |
return $slag; | |
} | |
/* Пример использования: */ | |
header('Content-Type: text/html; charset=utf-8'); | |
$lat_zagolovok = "Berker Вставки для серий B.1,B.3,B.7"; | |
$lat_slug = sozdat_slag($lat_zagolovok); | |
print $lat_slug; // - вернет "google-the-search-engine". | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment