Reputation: 35361
Is there a possibility that you can check a string if it needs to be UTF8 decoded in PHP?
Upvotes: 1
Views: 180
Reputation: 1635
You can determine if the string is using UTF-8 encoding by using
mb_detect_encoding($str, 'UTF-8');
Upvotes: 1
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