我正在制作拉丁语和cyrilic的搜索引擎,通过编写它会显示两种语言的结果。一切都适用于我的脚本但问题是“S”,“C”当人们写他们有2意思是字母,拉丁语“S”等于cyrilic“С”和“Ш”或拉丁语“C”到“Ц”和“Ч”。所以任何人都可以帮助我。谢谢!
我的剧本:
$cyrToLat = array(
"а"=>"a","б"=>"b","в"=>"v","г"=>"g","д"=>"d","ѓ"=>"gj","е"=>"e","ж"=>"zh","з"=>"z","ѕ"=>"s",
"и"=>"i","ј"=>"j","к"=>"k","л"=>"l","љ"=>"lj","м"=>"m","н"=>"n","њ"=>"nj","о"=>"o","п"=>"p",
"р"=>"r","с"=>"s","т"=>"t","ќ"=>"kj","у"=>"u","ф"=>"f","х"=>"h","ц"=>"c","џ"=>"dz","ч"=>"ch",
"ш"=>"sh","А"=>"A","Б"=>"B","В"=>"V","Г"=>"G","Д"=>"D","Ѓ"=>"GJ","Е"=>"E","Ж"=>"ZH","З"=>"Z",
"Ѕ"=>"S","И"=>"I","Ј"=>"J","К"=>"K","Л"=>"L","Љ"=>"LJ","М"=>"M","Н"=>"N","Њ"=>"NJ","О"=>"O",
"П"=>"P","Р"=>"R","С"=>"S","Т"=>"T","Ќ"=>"KJ","У"=>"U","Ф"=>"F","Х"=>"H","Ц"=>"C","Џ"=>"DZ",
"Ч"=>"CH","Ш"=>"SH","Ѓ"=>"Gj","Ж"=>"Zh","Љ"=>"Lj","Њ"=>"Nj","Ќ"=>"Kj","Џ"=>"Dz","Ч"=>"Ch",
"Ч"=>"C","Ш"=>"S"
);
$latToCyr = array(
"a"=>"а","b"=>"б","v"=>"в","g"=>"г","d"=>"д","gj"=>"ѓ","e"=>"е","zh"=>"ж","z"=>"з","s"=>"ѕ",
"i"=>"и","j"=>"ј","k"=>"к","l"=>"л","lj"=>"љ","m"=>"м","n"=>"н","nj"=>"њ","o"=>"о","p"=>"п",
"r"=>"р","s"=>"с","t"=>"т","kj"=>"ќ","u"=>"у","f"=>"ф","h"=>"х","c"=>"ц","dz"=>"џ","ch"=>"ч",
"sh"=>"ш","A"=>"А","B"=>"Б","V"=>"В","G"=>"Г","D"=>"Д","GJ"=>"Ѓ","E"=>"Е","ZH"=>"Ж","Z"=>"З",
"S"=>"Ѕ","I"=>"И","J"=>"Ј","K"=>"К","L"=>"Л","LJ"=>"Љ","M"=>"М","N"=>"Н","NJ"=>"Њ","O"=>"О",
"P"=>"П","R"=>"Р","S"=>"С","T"=>"Т","KJ"=>"Ќ","U"=>"У","F"=>"Ф","H"=>"Х","C"=>"Ц","DZ"=>"Џ",
"CH"=>"Ч","SH"=>"Ш","Gj"=>"Ѓ","Zh"=>"Ж","Lj"=>"Љ","Nj"=>"Њ","Kj"=>"Ќ","Dz"=>"Џ","Ch"=>"Ч",
"C"=>"Ч","S"=>"Ш"
);
}
$word = strip_tags(htmlentities(mysql_real_escape_string($_POST['search'])));
$keyword_lat = strtr($word,$cyrToLat);
$keyword_cyr = strtr($word,$latToCyr);
好的,这是工作代码。由于oleksii.svarychevskyi
,我找到了解决问题的方法if(isset($_POST['submit'])){
$cyrToLat = array(
"а"=>"a","б"=>"b","в"=>"v","г"=>"g","д"=>"d","ѓ"=>"gj","е"=>"e","ж"=>"zh","з"=>"z","ѕ"=>"s",
"и"=>"i","ј"=>"j","к"=>"k","л"=>"l","љ"=>"lj","м"=>"m","н"=>"n","њ"=>"nj","о"=>"o","п"=>"p",
"р"=>"r","с"=>"s","т"=>"t","ќ"=>"kj","у"=>"u","ф"=>"f","х"=>"h","ц"=>"c","џ"=>"dz","ч"=>"ch",
"ш"=>"sh","А"=>"A","Б"=>"B","В"=>"V","Г"=>"G","Д"=>"D","Ѓ"=>"GJ","Е"=>"E","Ж"=>"ZH","З"=>"Z",
"Ѕ"=>"S","И"=>"I","Ј"=>"J","К"=>"K","Л"=>"L","Љ"=>"LJ","М"=>"M","Н"=>"N","Њ"=>"NJ","О"=>"O",
"П"=>"P","Р"=>"R","С"=>"S","Т"=>"T","Ќ"=>"KJ","У"=>"U","Ф"=>"F","Х"=>"H","Ц"=>"C","Џ"=>"DZ",
"Ч"=>"CH","Ш"=>"SH","Ѓ"=>"Gj","Ж"=>"Zh","Љ"=>"Lj","Њ"=>"Nj","Ќ"=>"Kj","Џ"=>"Dz","Ч"=>"Ch",
"Ч"=>"C","Ш"=>"S"
);
$cyrToLatArr = array("ч"=>"c");
$latToCyr = array(
"a"=>"а","b"=>"б","v"=>"в","g"=>"г","d"=>"д","gj"=>"ѓ","e"=>"е","zh"=>"ж","z"=>"з","s"=>"ѕ",
"i"=>"и","j"=>"ј","k"=>"к","l"=>"л","lj"=>"љ","m"=>"м","n"=>"н","nj"=>"њ","o"=>"о","p"=>"п",
"r"=>"р","s"=>"с","t"=>"т","kj"=>"ќ","u"=>"у","f"=>"ф","h"=>"х","c"=>"ц","dz"=>"џ","ch"=>"ч",
"sh"=>"ш","A"=>"А","B"=>"Б","V"=>"В","G"=>"Г","D"=>"Д","GJ"=>"Ѓ","E"=>"Е","ZH"=>"Ж","Z"=>"З",
"S"=>"Ѕ","I"=>"И","J"=>"Ј","K"=>"К","L"=>"Л","LJ"=>"Љ","M"=>"М","N"=>"Н","NJ"=>"Њ","O"=>"О",
"P"=>"П","R"=>"Р","S"=>"С","T"=>"Т","KJ"=>"Ќ","U"=>"У","F"=>"Ф","H"=>"Х","C"=>"Ц","DZ"=>"Џ",
"CH"=>"Ч","SH"=>"Ш","Gj"=>"Ѓ","Zh"=>"Ж","Lj"=>"Љ","Nj"=>"Њ","Kj"=>"Ќ","Dz"=>"Џ","Ch"=>"Ч",
"C"=>"Ч","S"=>"Ш",
);
$latToCyrArr = array("c"=>"ч");
$word = strip_tags(htmlentities(mysql_real_escape_string($_POST['search'])));
$m_lat = array_merge($latToCyr, $latToCyrArr,$cyrToLatArr);
$keyword_lat = strtr($word,$m_lat);
$keyword_cyr = strtr($word,$cyrToLat);
答案 0 :(得分:0)
我已经考虑了你的代码。 $ latToCyrArr现在包含可能转换的数组。但是,所有具有多个值的符号都需要移动到单独的数组中。因此,您将获得可能的翻译数组。
$latToCyrABase = array(
"a"=>"а","b"=>"б","v"=>"в","g"=>"г","d"=>"д","gj"=>"ѓ","e"=>"е","zh"=>"ж","z"=>"з","s"=>"ѕ",
"i"=>"и","j"=>"ј","k"=>"к","l"=>"л","lj"=>"љ","m"=>"м","n"=>"н","nj"=>"њ","o"=>"о","p"=>"п",
"r"=>"р","s"=>"с","t"=>"т","kj"=>"ќ","u"=>"у","f"=>"ф","h"=>"х","c"=>"ц","dz"=>"џ","ch"=>"ч",
"sh"=>"ш","A"=>"А","B"=>"Б","V"=>"В","G"=>"Г","D"=>"Д","GJ"=>"Ѓ","E"=>"Е","ZH"=>"Ж","Z"=>"З",
"S"=>"Ѕ","I"=>"И","J"=>"Ј","K"=>"К","L"=>"Л","LJ"=>"Љ","M"=>"М","N"=>"Н","NJ"=>"Њ","O"=>"О",
"P"=>"П","R"=>"Р","S"=>"С","T"=>"Т","KJ"=>"Ќ","U"=>"У","F"=>"Ф","H"=>"Х","C"=>"Ц","DZ"=>"Џ",
"CH"=>"Ч","SH"=>"Ш","Gj"=>"Ѓ","Zh"=>"Ж","Lj"=>"Љ","Nj"=>"Њ","Kj"=>"Ќ","Dz"=>"Џ","Ch"=>"Ч"
);
$latToCyrArr = array(
array("C"=>"Ч", "c"=>"ч"),
array("S"=>"Ш")
);
$word = 'covek';
$keyword_lat_arr = array();
foreach ($latToCyrArr as $latToCyr) {
$keyword_lat = strtr($word, array_merge($latToCyrABase, $latToCyr));
if (!in_array($keyword_lat, $keyword_lat_arr)) {
$keyword_lat_arr[] = $keyword_lat;
}
}
print_r($keyword_lat_arr);
for sql query
$like = array();
//for every variable which is array do this
foreach ($keyword_lat as $value) {
$like[] = "jtitle LIKE '%".$value%."'";
}
foreach ($keyword_cyr as $value) {
$like[] = "jtitle LIKE '%".$value%."'";
}
$like[] = "jtitle LIKE '".%$word%."'";
$like = implode(' OR ', $like);
$sql = "SELECT * FROM adverts WHERE $like ORDER BY adverts.id DESC";