PHP代码如下:
trim(strtolower(utf8_encode($res->translation))) == trim(strtolower(utf8_encode($ph)))
返回false,例如:$res->translation = "Bottines À Talons Hauts"
和$ph = "bottines à talons hauts"
。问题应该出现在一个奇怪的À
字母中,因为其他单词完全匹配。
需要注意的是,$res->translation
来自MySQL,$ph
是HTML页面中文本区的一个短语。
有什么想法吗?
http://www.php.net/manual/en/function.strtolower.php
返回将所有字母字符转换为小写的字符串。
请注意,"字母"由当前区域设置决定。这意味着在默认的";C";语言环境中,元音变音符-A(É)等字符将不会被转换。
这应该使用mb_strtlower和强制UTF-8 来解决
trim(mb_strtolower(utf8_encode($res->translation),'UTF-8')) == trim(mb_strtolower(utf8_encode($ph),'UTF-8'))
可能需要使用utf8编码建立数据库连接。
建立连接时请尝试以下操作:
$link = mysql_connect('localhost', 'user', 'password');
mysql_set_charset('utf8',$link);
注意:最好使用mysqli或PDO,尽管