Strange string comparison

I am comparing a row from a database with a list of rows in an array:

if (in_array($entry, array('Söme string', 'other-string')))

This works for other-string, but not for Söme string, the main difference is that there is an umlaut and an html object in this line. If $entry Söme stringin the database, the comparison is not performed, although it must be the same row.

I also tried a strcmpdirect comparison using ===and ==, but the comparison is always negative. I also tried utf8_encodebefore the comparison, but did nothing.

The database uses UTF-8, I retrieve the data using the Drupal API functions, and my php file is also encoded with UTF-8. If I type $entryand Söme stringthe output HTML, they are indistinguishable.

Any idea what might cause this behavior?

Update

Thanks for the help. It seems to be  transformed on the way and stored as a real inextricable space in the database, and not as an HTML object. Printing it converts back to an HTML object (or Firebug does it when I look at it).

The result of var_dump () (using the print function taken from the resulting html source):

$entry: string(14) "Söme string"

"Söme string": string(18) "Söme string"

(I edited the line as real containing the name)

Update 2

I changed the line to "Some string", and here is the output

var_dump(bin2hex($entry));
var_dump(bin2hex('Some string'));

$entry: string(24) "536f6d65c2a0737472696e67"
"Some string": string(32) "536f6d65266e6273703b737472696e67"
+3
source share
2 answers

Then the lines do not match. Maybe:

  • $entry has actual space instead of inextricable space.
  • HTML  , .
  • ö , - .

var_dump $entry.

+4

, $entry UTF-8 (0xc2a0). html_entities , . :

htmlentities($entry, ENT_QUOTES, 'UTF-8')
0

Source: https://habr.com/ru/post/1763745/


All Articles