stripos returns false when special characters is used

点点圈 提交于 2019-11-26 22:03:30

问题


I am using the stripos function to check if a string is located inside another string, ignoring any cases.

Here is the problem:

stripos("ø", "Ø")

returns false. While

stripos("Ø", "Ø")

returns true.

As you might see, it looks like the function does NOT do a case-insensitive search in this case.

The function has the same problems with characters like Ææ and Åå. These are Danish characters.


回答1:


Use mb_stripos() instead. It's character set aware and will handle multi-byte character sets. stripos() is a holdover from the good old days when there was only ASCII and all chars were only 1 byte.




回答2:


You need mb_stripos.




回答3:


mb_stripos will take care of this.




回答4:


As the other solutions say, try first with mb_stripos(). But if using this function doesn't help, check the encoding of your php file. Convert it to UTF-8 and save it. That did the trick for me after hours of research.



来源:https://stackoverflow.com/questions/5487917/stripos-returns-false-when-special-characters-is-used

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