MacMac
MacMac

Reputation: 35361

How to determine a string that needs to be UTF8 decoded

Is there a possibility that you can check a string if it needs to be UTF8 decoded in PHP?

Upvotes: 1

Views: 180

Answers (2)

toopay
toopay

Reputation: 1635

You can determine if the string is using UTF-8 encoding by using

 mb_detect_encoding($str, 'UTF-8');

Upvotes: 1

Gumbo
Gumbo

Reputation: 655795

You can use mb_detect_encoding to check if the string is already encoded in UTF-8:

mb_detect_encoding($str, 'UTF-8', true)

This returns false if the string is not valid UTF-8.

Upvotes: 3

Related Questions