Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

php - UTF-8 problem when saving to mysql

My website is using charset iso 8859 1

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

when user post chinese character, it will be saved into the database as & # 2 0 3 2 0 ; & # 2 2 9 0 9 ; which will output as the chinese character when retrieved.

I need to set my website to UTF-8

when user post chinese character, it will be saved as some funky character in the mysql, and when retrieved, some characters are correct but some are wrong.

my question is, after i set to UTF-8, how to i make mysql save the text as # 2 0 3 2 0 ; & # 2 2 9 0 9 ; instead of funky chars.

i tried to use htmlentities. it's not working correctly.

my script is using

$message = htmlentities(strip_tags(mysql_real_escape_string($_POST['message']),'<img><vid>')); 

when it's saved to mysql it is like this 你好 when it's retrieved to be display is like this ?? ?¥? <---- is the funky character that is stored in mysql previously

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

i been seeing lots of encoding related issues the owner should google a bit before posting

general check list:

  1. mysql table schema to use utf-8
  2. mysql clients connection to use utf-8 mysql --default-character-set=utf8
  3. php mysqli_set_charset to utf-8
  4. html encoding to utf-8
  5. putty, emac clients... to be in utf-8

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...