Answer the question
In order to leave comments, you need to log in
How to transliterate in both directions?
There is a transliteration function, but the problem is that if there is a b in the string, the b (soft and hard sign) is replaced in the transliteration by ' and '', which does not suit me, because I pass the string to the url and pull out the string from this url and back I translate into Russian.
What characters can replace the hard and soft signs so that there are no quotes and the string is changed to Russian in its original state?
function TranslitURL ($text, $translits = 'ru_en') {
$translit = array(
'а' => 'a', 'б' => 'b', 'в' => 'v',
'г' => 'g', 'д' => 'd', 'е' => 'e',
'ё' => 'yo', 'ж' => 'zh', 'з' => 'z',
'и' => 'i', 'й' => 'j', 'к' => 'k',
'л' => 'l', 'м' => 'm', 'н' => 'n',
'о' => 'o', 'п' => 'p', 'р' => 'r',
'с' => 's', 'т' => 't', 'у' => 'u',
'ф' => 'f', 'х' => 'x', 'ц' => 'c',
'ч' => 'ch', 'ш' => 'sh', 'щ' => 'shh',
'ь' => '\'', 'ы' => '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', 'Х' => 'X', 'Ц' => 'C',
'Ч' => 'CH', 'Ш' => 'SH', 'Щ' => 'SHH',
'Ь' => '\'', 'Ы' => 'Y\'', 'Ъ' => '\'\'',
'Э' => 'E', 'Ю' => 'YU', 'Я' => 'YA',
);
if($translits == 'en_ru') {
$word = strtr($text, array_flip($translit));
$word = str_replace( "_", " ", $word);
} else {
$word = strtr($text, $translit);
$word = str_replace( " ", "_", $word);
}
return $word;
}
Answer the question
In order to leave comments, you need to log in
if there is a ъ (soft and hard sign) in the string, it is replaced in transliteration with ' and '', which does not suit me, because I pass the string to the url and already from this url I pull out the string and translate it back into RussianWhy? According to RFC3986 , all characters that are not allowed in a URL must be encoded, and PHP provides the
rawurlencode()
and functions for this rawurldecode()
. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question