1

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.

flero
  • 70
  • 1
  • 8
  • 2
    The string with the 0xf3 value is encoded as Latin1, the string with 0xc3 0xb3 is encoded in UTF-8. Make sure to [configure your database connection](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) to return UTF-8. – nwellnhof May 04 '16 at 15:16

1 Answers1

1

As nwellnhof said setting the charset on the connection solved the problem. In my case i had to use mysql_set_charset

Community
  • 1
  • 1
flero
  • 70
  • 1
  • 8