我正在用土耳其语搜索PHP.在土耳其语字母中,有“ i”和“ı”小写字符.还具有“ I”和“İ”大写字符.
在正则表达式函数中找不到MySQL选择查询土耳其语字符,例如:İ-ı..我的搜索列数据类型字符集UTF-8 general_ci.
我在等你的答案.提前致谢.
最佳答案
您可以通过以下方式解决土耳其字符问题.
原文链接:https://www.f2er.com/mysql/531928.htmlfunction searchBarReplaceChar() {
searchInput = $.trim($('input[name="replaceChar"]').val());
let charMap = {
Ç: '[CÇ]+',C: '[CÇ]+',Ö: '[OÖ]+',O: '[OÖ]+',Ş: '[SŞ]+',S: '[SŞ]+',İ: '[Iİ]+',I: '[Iİ]+',Ü: '[UÜ]+',U: '[UÜ]+',Ğ: '[GĞ]+',G: '[GĞ]+',ç: '[cç]+',c: '[cç]+',ö: '[oö]+',o: '[oö]+',ş: '[sş]+',s: '[sş]+',ı: '[ıi]+',i: '[ıi]+',ü: '[uü]+',u: '[uü]+',ğ: '[gğ]+',g: '[gğ]+',};
let str_array = searchInput.split('');
for (let i = 0,len = str_array.length; i < len; i++) {
str_array[i] = charMap[str_array[i]] || str_array[i];
}
searchInput = str_array.join('');
let replaceChar = searchInput.replace(/[]/gi,"");
let lastChar = replaceChar.slice(-1);
if (lastChar === '+') {
replaceChar = replaceChar.slice(0,-1);
}
$('.result').text(replaceChar);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" name="replaceChar" value="şehir bu gece çok güzel" />
<p class="result"></p>
<button type="submit" onclick="searchBarReplaceChar()" >Send</button>
public function search_regexp() {
$regexp = str_replace('i','İ',$_POST['get_replace_result']);
$regexp = str_replace('ı','I',$regexp);
$regexp = mb_strtoupper($regexp,"UTF-8");
$sql_query = "SELECT * FROM your_table WHERE example_column regexp '$regexp'";
// $sql_query = "SELECT * FROM your_table WHERE example_column regexp '[SŞ]+EH[Iİ]+R B[UÜ]+ [GĞ]+E[CÇ]+E [CÇ]+[OÖ]+K [GĞ]+[UÜ]+ZEL'";
}
不要忘记这一点,MysqL数据库在您的表列中的数据类型为字符集utf8_turkish_ci
祝你好运