Comparing two unicode strings in PHP

泄露秘密 提交于 2019-12-02 00:01:08

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).

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!