Reputation: 70
i'm currently having some problem with Strings comparison between PHP and Mysql strings. I have a variable that comes from a Mysql DB and i compare it with an hardcoded one:
$string_from_mysql = "Información" //comes from DB read;
$test_string = "Información" //hard coded via text editor;
$test = strpos($string_from_mysql,$test_string); -> Returns false
The problem seems to be related to the ó, in $string_from_mysql the character has the 0x00F3 value while on $test_string the character is 0xC3 0xB3. This, obviously, leads to the "false" return value of strpos. The character is "canonically equivalent" but it does not have the same value.
What is the approach in this kind of situation? I found out the Normalizer PHP class, is it the only viable and clean solution?
Thanks.
Upvotes: 1
Views: 483
Reputation: 70
As nwellnhof said setting the charset on the connection solved the problem. In my case i had to use mysql_set_charset
Upvotes: 1