Comparing two unicode strings in PHP

前端 未结 2 924
一生所求
一生所求 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 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).

提交回复
热议问题