UTF8编码带有特殊的外来字符
PHP piece of code like this:
trim(strtolower(utf8_encode($res->translation))) == trim(strtolower(utf8_encode($ph)))
returns false if, for example:$res->translation = "Bottines À Talons Hauts"
and $ph = "bottines à talons hauts"
. The problem should be in a weird À
letter, as other words match perfectly.
It needs to be mentioned that $res->translation
comes from MySQL and $ph
is a phrase from textarea in HTML page.
Any ideas?
http://www.php.net/manual/en/function.strtolower.php
Returns string with all alphabetic characters converted to lowercase.
Note that 'alphabetic' is determined by the current locale. This means that in i.e. the default "C" locale, characters such as umlaut-A (Ä) will not be converted.
This should be solved using mb_strtolower and forcing UTF-8
trim(mb_strtolower(utf8_encode($res->translation),'UTF-8')) == trim(mb_strtolower(utf8_encode($ph),'UTF-8'))
May be your database connection needs to be established using utf8 encoding.
Try following when establishing your connection:
$link = mysql_connect('localhost', 'user', 'password');
mysql_set_charset('utf8',$link);
Note: Better to use mysqli or PDO, though