I'm building a PHP web application, and it works in UTF-8. The database is UTF-8, the pages are served as UTF-8 and I set the charset using a meta tag to UTF-8. Of course, with users using Internet Explorer, and copying & pasting from Microsoft Office, I somehow manage to get not UTF-8 input occasionally.
The ideal solution would be to throw an HTTP 400 Bad Request
error, but obviously I can't do that. The next best thing is converting $_GET
, $_POST
and $_REQUEST
to UTF-8. Is there anyway to see what character encoding the input is in so I can pass it off to iconv
? If not, what's the best solution for doing this?
Check out mb_detect_encoding()
Example:
$utf8 = iconv(mb_detect_encoding($input), 'UTF-8', $input);
There's also utf8_encode()
if you guarantee that the string is input as ISO-8859-1.
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