I have setup a MySQL DB with collation as UTF-8.
I have set the content type in the header of php – header(‘Content-type: text/html; charset=UTF-8’);
And I’ve added the following to all my web pages - <meta http-equiv=”Content-type” value=”text/html; charset=”UTF-8” />
My site has forms which take user input and insert/update DB rows with this data. How do I make sure the user input is UTF-8 and not any other charset.
You can detect the encoding with mb_detect_encoding, if you hadn’t seen that. However, users should be submitting UTF-8 all the time so conversion should not be required.
If its not UTF-8 am I correct in saying the next step would be to detect the encoding used then to convert the string to UTF-8 using mb_convert_encoding.
That function only works with text entered in ISO-8859-1 charset.
I’m wondering do I need to do anything as I have informed the browser, PHP and MySQL that the site is UTF-8 therefore when a user enters text via input textbox does the conversion automatically happen?