In my website there is a form with a simple textarea for people to post comments. The problem is that sometimes I receive information in UTF-8 and sometimes in ISO. Is it possible to control that?
Maybe I am doing something wrong, but is it possible that the browser changes the codification of the data it sends?
But... check before encoding, if string is already UTF-8. Else you double-encode it.
function str_to_utf8 ($string) {
if (mb_detect_encoding($string, 'UTF-8', true) === false) {
$string = utf8_encode($string);
}
return $str;
}
Or use
$string = utf8_encode(utf8_decode($string));
So you do not double-encode a string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With