кирилица и латиница заменяне проблем

Contacte

Registered
Защо не ми изкарва нищо
неможех да открия грежка в кода помагайте
Код:
<?php
function kirilica($kir){
$specialchars = array("ч" => "ch","Ч" => "CH","ш" => "sh","Ш" => "SH","щ" => "sht","Щ" => "SHT","ю" => "iu","Ю" => "IU","я" => "q","Я" => "Q", "ьо" => "jzo");
$kirilica=array(
'А','Б','В','Г','Д','Е','Ж','З','И','Й','К','Л','М','Н','О',
'П','Р','С','Т','У','Ф','Х','Ц','Ъ','Ь','Я',
'а','б','в','г','д','е','ж','з','и','й','к','л','м','н','о',
'п','р','с','т','у','ф','х','ц','ъ','ь','я'); //масива със кирилица, съответстващ на този с латиница
$latinica=array(
'A','B','V','G','D','E','Zh','Z','I','J','K','L','M','N','O',
'P','R','S','T','U','F','H','C','Y','J','Q',
'a','b','v','g','d','e','zh','z','i','j','k','l','m','n','o',
'p','r','s','t','u','f','h','c','y','j','q'); //масива със латинските букви
$bbc_num=count($kirilica); //бройм елементите във масива $kirilica
$loop=0;
while($loop<$bbc_num){
$kir2 = strtr($kir, $specialchars);
$kir = str_replace($kirilica[$loop], $latinica[$loop], $kir2); //заместваме буквите
$loop++;
}
return $kir2;
}

function latinica($lat){
$specialchars = array("ch" => "ч", "CH" => "Ч", "sh" => "ш", "SH" => "Ш", "sht" => "щ", "SHT" => "Щ", "iu" => "ю", "IU" => "Ю", "q" => "я", "Q" => "Я", "jzo" => "ьо");
$latinica=array(
'A','B','V','G','D','E','Zh','Z','I','J','K','L','M','N','O',
'P','R','S','T','U','F','H','C','Y','J','Q',
'a','b','v','g','d','e','zh','z','i','j','k','l','m','n','o',
'p','r','s','t','u','f','h','c','y','j','q'); //масива със латинските букви
$kirilica=array(
'А','Б','В','Г','Д','Е','Ж','З','И','Й','К','Л','М','Н','О',
'П','Р','С','Т','У','Ф','Х','Ц','Ъ','Ь','Я',
'а','б','в','г','д','е','ж','з','и','й','к','л','м','н','о',
'п','р','с','т','у','ф','х','ц','ъ','ь','я'); //масива със кирилица, съответстващ на този с латиница
$bbc_num=count($latinica); //бройм елементите във масива $latinica
$loop=0;
while($loop<$bbc_num){
$lat2 = strtr($lat, $specialchars);
$lat = str_replace($latinica[$loop], $kirilica[$loop], $lat2); //заместваме буквите
$loop++;
}
return $lat2;
}

$string = "Шакира";
$string2 = kirilica($string2);

$string3 = "Shakira";
$string4 = latinica($string4);

echo "$string2 <br><br>";

echo "$string4 <br>";
?>
 
Код:
<?php
function kirilica($kir){
$specialchars = array("ч" => "ch","Ч" => "CH","ш" => "sh","Ш" => "SH","щ" => "sht","Щ" => "SHT","ю" => "iu","Ю" => "IU","я" => "q","Я" => "Q", "ьо" => "jzo");
$kirilica=array(
'А','Б','В','Г','Д','Е','Ж','З','И','Й','К','Л','М','Н','О',
'П','Р','С','Т','У','Ф','Х','Ц','Ъ','Ь','Я',
'а','б','в','г','д','е','ж','з','и','й','к','л','м','н','о',
'п','р','с','т','у','ф','х','ц','ъ','ь','я'); //масива със кирилица, съответстващ на този с латиница
$latinica=array(
'A','B','V','G','D','E','Zh','Z','I','J','K','L','M','N','O',
'P','R','S','T','U','F','H','C','Y','J','Q',
'a','b','v','g','d','e','zh','z','i','j','k','l','m','n','o',
'p','r','s','t','u','f','h','c','y','j','q'); //масива със латинските букви
$bbc_num=count($kirilica); //бройм елементите във масива $kirilica
$loop=0;
while($loop<$bbc_num){
$kir2 = strtr($kir, $specialchars);
$kir = str_replace($kirilica[$loop], $latinica[$loop], $kir2); //заместваме буквите
$loop++;
}
return $kir2;
}

function latinica($lat){
$specialchars = array("ch" => "ч", "CH" => "Ч", "sh" => "ш", "SH" => "Ш", "sht" => "щ", "SHT" => "Щ", "iu" => "ю", "IU" => "Ю", "q" => "я", "Q" => "Я", "jzo" => "ьо");
$latinica=array(
'A','B','V','G','D','E','Zh','Z','I','J','K','L','M','N','O',
'P','R','S','T','U','F','H','C','Y','J','Q',
'a','b','v','g','d','e','zh','z','i','j','k','l','m','n','o',
'p','r','s','t','u','f','h','c','y','j','q'); //масива със латинските букви
$kirilica=array(
'А','Б','В','Г','Д','Е','Ж','З','И','Й','К','Л','М','Н','О',
'П','Р','С','Т','У','Ф','Х','Ц','Ъ','Ь','Я',
'а','б','в','г','д','е','ж','з','и','й','к','л','м','н','о',
'п','р','с','т','у','ф','х','ц','ъ','ь','я'); //масива със кирилица, съответстващ на този с латиница
$bbc_num=count($latinica); //бройм елементите във масива $latinica
$loop=0;
while($loop<$bbc_num){
$lat2 = strtr($lat, $specialchars);
$lat = str_replace($latinica[$loop], $kirilica[$loop], $lat2); //заместваме буквите
$loop++;
}
return $lat2;
}

$string = "Шакира";
$string2 = kirilica($string);

$string3 = "Shakira";
$string4 = latinica($string3);

echo "$string2 <br><br>";

echo "$string4 <br>";
?>
 
Аз го правя така:


Код:
//BG фонетика
function bgfonetika($text)
{
$text=str_replace('а','a', $text);
$text=str_replace('б','b', $text);
$text=str_replace('в','v', $text);
$text=str_replace('г','g', $text);
$text=str_replace('д','d', $text);
$text=str_replace('е','e', $text);
$text=str_replace('ж','j', $text);
$text=str_replace('з','z', $text);
$text=str_replace('и','i', $text);
$text=str_replace('й','i', $text);
$text=str_replace('к','k', $text);
$text=str_replace('л','l', $text);
$text=str_replace('м','m', $text);
$text=str_replace('н','n', $text);
$text=str_replace('о','o', $text);
$text=str_replace('п','p', $text);
$text=str_replace('р','r', $text);
$text=str_replace('с','s', $text);
$text=str_replace('т','t', $text);
$text=str_replace('у','u', $text);
$text=str_replace('ф','f', $text);
$text=str_replace('х','h', $text);
$text=str_replace('ц','c', $text);
$text=str_replace('ч','ch', $text);
$text=str_replace('ш','sh', $text);
$text=str_replace('щ','st', $text);
$text=str_replace('ъ','y', $text);
$text=str_replace('ь','i', $text);
$text=str_replace('ю','iu', $text);
$text=str_replace('я','q', $text);

$text=str_replace('А','A', $text);
$text=str_replace('Б','B', $text);
$text=str_replace('В','V', $text);
$text=str_replace('Г','G', $text);
$text=str_replace('Д','D', $text);
$text=str_replace('Е','E', $text);
$text=str_replace('Ж','J', $text);
$text=str_replace('З','Z', $text);
$text=str_replace('И','I', $text);
$text=str_replace('Й','I', $text);
$text=str_replace('К','K', $text);
$text=str_replace('Л','L', $text);
$text=str_replace('М','M', $text);
$text=str_replace('Н','N', $text);
$text=str_replace('О','O', $text);
$text=str_replace('П','P', $text);
$text=str_replace('Р','R', $text);
$text=str_replace('С','S', $text);
$text=str_replace('Т','T', $text);
$text=str_replace('У','U', $text);
$text=str_replace('Ф','F', $text);
$text=str_replace('Х','H', $text);
$text=str_replace('Ц','C', $text);
$text=str_replace('Ч','Ch', $text);
$text=str_replace('Ш','Sh', $text);
$text=str_replace('Щ','St', $text);
$text=str_replace('Ъ','Y', $text);
$text=str_replace('Ь','I', $text);
$text=str_replace('Ю','Iu', $text);
$text=str_replace('Я','Q', $text);


$text=str_replace('&','and', $text);


return $text;
}
//BG фонетика

function bgconv($text)
{
$text=str_replace('a','а', $text);
$text=str_replace('b','б', $text);
$text=str_replace('c','ц', $text);
$text=str_replace('d','д', $text);
$text=str_replace('e','е', $text);
$text=str_replace('f','ф', $text);
$text=str_replace('g','г', $text);
$text=str_replace('h','х', $text);
$text=str_replace('i','и', $text);
$text=str_replace('j','ж', $text);
$text=str_replace('k','к', $text);
$text=str_replace('l','л', $text);
$text=str_replace('m','м', $text);
$text=str_replace('n','н', $text);
$text=str_replace('o','о', $text);
$text=str_replace('p','п', $text);
$text=str_replace('q','я', $text);
$text=str_replace('r','р', $text);
$text=str_replace('s','с', $text);
$text=str_replace('t','т', $text);
$text=str_replace('u','у', $text);
$text=str_replace('w','в', $text);
$text=str_replace('x','ь', $text);
$text=str_replace('y','ъ', $text);
$text=str_replace('z','з', $text);
$text=str_replace('v','в', $text);
$text=str_replace('сх','ш', $text);
$text=str_replace('схт','щ', $text);
$text=str_replace('иу','ю', $text);
$text=str_replace('иа','Я', $text);
$text=str_replace('цх','ч', $text);
$text=str_replace('цхт','щ', $text);


$text=str_replace('A','А', $text);
$text=str_replace('B','Б', $text);
$text=str_replace('C','Ц', $text);
$text=str_replace('D','Д', $text);
$text=str_replace('E','Е', $text);
$text=str_replace('F','Ф', $text);
$text=str_replace('G','Г', $text);
$text=str_replace('H','Х', $text);
$text=str_replace('I','И', $text);
$text=str_replace('J','Ж', $text);
$text=str_replace('K','К', $text);
$text=str_replace('L','Л', $text);
$text=str_replace('M','М', $text);
$text=str_replace('N','Н', $text);
$text=str_replace('O','О', $text);
$text=str_replace('P','П', $text);
$text=str_replace('Q','Я', $text);
$text=str_replace('R','Р', $text);
$text=str_replace('S','С', $text);
$text=str_replace('T','Т', $text);
$text=str_replace('U','У', $text);
$text=str_replace('W','В', $text);
$text=str_replace('X','Ь', $text);
$text=str_replace('Y','Ъ', $text);
$text=str_replace('Z','З', $text);
$text=str_replace('V','В', $text);
$text=str_replace('Схт','Щ', $text);
$text=str_replace('Сх','Ш', $text);
$text=str_replace('Иу','Ю', $text);
$text=str_replace('Иа','Я', $text);
$text=str_replace('Цх','ч', $text);
$text=str_replace('Цхт','Щ', $text);


$text=str_replace('&','и', $text);


return $text;
}
 

Back
Горе