Reputation: 93
I cant seem to get these Chinese punctuation marks to work with my database (utf-8) when i do an echo of the query the marks look like this ���
in php i have already done
$text=mysql_real_escape_string(htmlentities($text));
so as a result they are not saved into the database correctly what can i do to fix this?
Thanks
Upvotes: 0
Views: 182
Reputation: 536349
Don't put HTML-encoded data in the database. It should be raw text until the time you spit it onto the page (at which point you should use htmlspecialchars()
.
You need to make sure that both your database and your page are using UTF-8:
Content-Type
of the page to text/html;charset=utf-8
by header or meta tag.You can get away with using a different encoding such as the default latin-1 on the database end and the connection if you treat it as bytes, but case-insensitive comparisons won't work if you do, so it's best to stick to UTF-8.
Upvotes: 0
Reputation: 1200
Try using using utf8_encode()
function while inserting into db and utf8_decode()
while printing the same.
Upvotes: 1
Reputation: 11278
besides if you want to use htmlentities, you have to set it to utf-8 encoding like that:
htmlentities($string,ENT_COMPAT,"UTF-8");
Upvotes: 0
Reputation: 1025
Executing mysql_query('SET NAMES utf-8'); before any operations with unicode will do the trick
Upvotes: 1
Reputation: 12962
Add the character 'N' before your string value.
Eg. select from test_table where temp=N'unicode string'
Upvotes: 0