7

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.

hakre
  • 193,403
  • 52
  • 435
  • 836
foens
  • 8,642
  • 2
  • 36
  • 48

4 Answers4

9

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.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • Why oh why is this function not stated as a related function to stripos... Then I would have been able to find out myself. Thanks for the help. – foens Mar 30 '11 at 15:12
  • 1
    You can suggest it to the PHP documentation maintainers. Those doc pages aren't frozen for all eternity. – Marc B Mar 30 '11 at 16:13
3

You need mb_stripos.

awm
  • 6,526
  • 25
  • 24
  • As much as I would like to accept both yours and Marc B's answer, I selected his since an explanation accompanied his answer. – foens Mar 30 '11 at 15:11
1

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.

Guscie
  • 2,278
  • 2
  • 26
  • 33
1

mb_stripos will take care of this.

k to the z
  • 3,217
  • 2
  • 27
  • 41