foens
foens

Reputation: 8682

How to make stripos() work with multibyte strings?

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.

Upvotes: 7

Views: 7389

Answers (4)

Gustavo Daniel
Gustavo Daniel

Reputation: 2488

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.

Upvotes: 1

k to the z
k to the z

Reputation: 3185

mb_stripos will take care of this.

Upvotes: 1

Marc B
Marc B

Reputation: 360882

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.

Upvotes: 9

awm
awm

Reputation: 6580

You need mb_stripos.

Upvotes: 3

Related Questions