Comparing two unicode strings in PHP

前端 未结 2 921
一生所求
一生所求 2021-01-20 18:15

I am stuck in comparing two unicode strings in PHP which both contain the special char \'ö\'. One string comes from $_GET, the other one is a filesystem\'s fold

相关标签:
2条回答
  • 2021-01-20 18:59

    Can you try parsing them through utf8_encode() and checking them there? PHP doesn't support unicode and therefore advises to use utf8_encode/decode for some basic Unicode features.

    http://php.net/manual/en/language.types.string.php

    0 讨论(0)
  • 2021-01-20 19:15

    See here: http://en.wikipedia.org/wiki/Unicode_equivalence and use this: http://www.php.net/manual/en/class.normalizer.php

    You probably have a decomposed character in the longer string, meaning an o and then a umlaut combining character which overlays the previous character.

    The normalizer function will fix things like that.

    As a side note you should always normalize your input if you are using it for equivalence (for example a username - you want to make sure two people don't choose the same username, even if the binary representation of the string happens to be different).

    0 讨论(0)
提交回复
热议问题