tags:

views:

81

answers:

5

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

A: 

Add the character 'N' before your string value.

Eg. select from test_table where temp=N'unicode string'

theycallmemorty
That's an MSSQL thing. MySQL doesn't work that way.
Michael Madsen
+1  A: 

Executing mysql_query('SET NAMES utf-8'); before any operations with unicode will do the trick

Vestel
A: 

besides if you want to use htmlentities, you have to set it to utf-8 encoding like that:

htmlentities($string,ENT_COMPAT,"UTF-8");
roman
+1  A: 

Try using using utf8_encode() function while inserting into db and utf8_decode() while printing the same.

Ashish Rajan
A: 

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:

  • ensure your tables are CREATEd with a UTF-8 collation;
  • use mysql_set_charset after connecting to ensure the connection between MySQL and PHP is UTF-8;
  • set the 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.

bobince