Stripos returns false when special characters are used

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

Here is the problem:

stripos("ø", "Ø") 

returns false. While

 stripos("Ø", "Ø") 

returns true.

As you can see, it seems that in this case the function does NOT do case insensitive search.

The function has the same problems with characters like Ææ and Γ…Γ₯. These are Danish characters.

+6
php string-search strpos
source share
4 answers

Use mb_stripos() . This character set knows and will handle multibyte character sets. stripos () is a delay from the good old days when there was only ASCII, and all characters were only 1 byte.

+8
source share

You need mb_stripos .

+3
source share

mb_stripos will take care of this.

+1
source share

As other solutions claim, try mb_stripos () first. But if using this function does not help, check the encoding of your php file. Convert it to UTF-8 and save. It helped me after hours of research.

+1
source share

All Articles