Question

I'm trying to change my encoding to utf-8, below is what I have so far.

Table Charset

my table

mbstring installed

extension=php_mbstring.dll

mbstring configured in php.ini

mbstring.language = Neutral
mbstring.internal_encoding = UTF-8
mbstring.encoding_translation = On /*updated it to mbstring.encoding_translation = 0*/
mbstring.http_input = auto         /*updated it to mbstring.http_input = pass*/
mbstring.http_output = UTF-8       /*updated it to mbstring.http_output = pass*/
mbstring.detect_order = auto  
mbstring.substitute_character
default_charset = UTF-8
mbstring.func_overload = 7

Header

header('Content-type: text/html; charset=UTF-8');

HTML meta tag

<meta http-equiv="Content-type" value="text/html; charset=UTF-8" />

HTML CODE

<label for="article_body_pun">Article (Foreign): </label>
<textarea cols="100" rows="10" name="article_body_pun"></textarea><br />

PHP

$article_body_pun   = $_REQUEST['article_body_pun'];

SQL

$insert_article = "INSERT INTO articles(article_body_pun) 
                      VALUES ('{$article_body_pun}'')";

PHP to insert

$article_query = mysqli_query($connectDB, $insert_article);

Data that should be stored -> 汉语

Original Data stored

汉è¯Â

Upon adding mysqli_set_charset($connectDB, "utf8"); as suggested by @Pekka 웃, output became (commented below as well)

æ±è¯

after some troubleshooting, data partially stored correctly.

�?语

tried checking the charset by mb_detect_encoding, and getting UTF-8 on the results pulled.

and upon checking the charset in firefox.

enter image description here

That seems to be correct, but still getting question marks on some characters. Any further suggestions to make this work?

Was it helpful?

Solution 2

I was able to fix the problem with help of a friend, the data was not inserted correctly from my HTML form to Database. Seems like my mbstring configurations were causing the problem, had to update the following:

mbstring.http_input = pass
mbstring.http_output = pass
mbstring.encoding_translation = 0

so the values are just reverted back to default and it worked perfectly.

Thanks to @Pekka 웃 and @Willem for their help.

OTHER TIPS

You're nearly there: make sure the mySQL connection is also encoded UTF-8.

Check out UTF-8 all the way through for details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top