我已经搜索了几个小时的问题,但没有找到适合我的答案,所以......我来了......
我是匈牙利人,我们在我们的语言中使用以下重音字符:áéíóöőúüű(当然还有大写字母)我想在 php 中进行智能搜索,允许用户输入搜索词并找到结果在 MySQl 表或搜索字段中是否有重音。所以...
我的 MySQL 表使用 utf8_hungarian_ci 我可以进行 php 转换,以便用户输入“Bla”或“blá”,它将返回“bla”,我们正在搜索 mySQL 数据库。
但我的问题是……我的数据库可能有一个“bla fér”或“bláter”字段条目。但是,如果我们使用“bla”(来自 PHP)进行搜索,它只会返回“bla fer”。如何将我正在搜索的字段转换为“bla fér”->“bla fer”和“bláter”->“blater”。所以本质上...
我想摆脱重音字符并将它们变成非重音字符。但当然,只是为了搜索。请帮忙!谢谢!
编辑:
<?php
$search = $_GET["search"]; // May contain áéíóöőúüű
$accented= array("Ö","ö","Ü","ü","ű","Ó","ó","O","o","Ú","ú","Á","á","U","u","É","é","Í","í"," ","+","'","ő", "Ű", "Ő", "ä","Ä","ű","Ű","ő","Ő");
$nonaccented=array("O","o","U","u","u","O","o","O","o","U","u","A","a","U","u","E","e","I","i","_","_","_","o", "U", "O", "a","A","u","u","o","o");
$search = str_replace($accented,$nonaccented,$search);
$query = "SELECT id, name FROM people WHERE name LIKE '%$search%'"; // Database column 'name' may also contain áéíóöőúüű
?>