PHP string comparison weirdness

zetSSaseWeeft

New Member
I'm comparing a string from the database to a list of strings in an array:\[code\]if (in_array($entry, array('S?me string', 'other-string')))\[/code\]This works for \[code\]other-string\[/code\], but not for \[code\]S?me string\[/code\], the main difference beeing that this string has an umlaut and an html entity in it. If \[code\]$entry\[/code\] is \[code\]S?me string\[/code\] in the database, the comparison fails, even though it should be the same string.I also tried \[code\]strcmp\[/code\] and direct comparison using \[code\]===\[/code\] and \[code\]==\[/code\], but the comparison is always negative. I also tried \[code\]utf8_encode\[/code\] before comparison, but that did nothing.The database is using UTF-8, I fetch the data using Drupal API functions and my php file is also UTF-8 encoded. If I print \[code\]$entry\[/code\] and \[code\]S?me string\[/code\] to the output HTML, they are indistinguishable.Any idea what could be causing this behaviour?UpdateThanks for the help. It seems the \[code\] \[/code\] is converted on the way and is stored as a real non-breaking space in the database, not as an HTML entity. Printing it converts it back to an HTML entity (or maybe Firebug does that when I look at it).The output of var_dump() (using print function, taken from resulting html source):\[code\]$entry: string(14) "S?me string"\[/code\]\[code\]"S?me string": string(18) "S?me string"\[/code\](I've edited the string as the real one contains a name)Update 2I've changed the string to \[code\]"Some string"\[/code\] and here's the output of \[code\]var_dump(bin2hex($entry));var_dump(bin2hex('Some string'));$entry: string(24) "536f6d65c2a0737472696e67""Some string": string(32) "536f6d65266e6273703b737472696e67"\[/code\]
 
Back
Top