Problem with characters in MySQL -> Php -> HTML
I have some text in a data table that contains this character: "•"
When I look at the text from phpMyAdmin, it looks OK, which means the right character is in the data, but if I query it with PHP and echo
it, even if I use htmlentities
, it will look like a weird square in IE and like � in Chrome.
I have the same problem with this two characters: “ and ”
What am I doing wrong?
Edit: I just tried utf8_encode and at least the ugly chars disappear, but this is still not what I want. My page's char encoding is utf8, same as phpMyAdmin's page 开发者_StackOverflow中文版encoding. There must be a way to show it right because phpMyAdmin does it
I would recommend using this query after connecting to the database:
mysqli_query($this->conn, 'SET NAMES \'utf8\'');
$this->conn
is your connection to the database.
further information on SET NAMES 'utf8'
can be obtained from MySQL Reference Manual Chapter 9.1.4
It's encoding issue, your page encoding might be different from the database encoding . either set both database and page to same encoding or use a function for example utf8_encode($variable) or utf8_decode
Edit: try add AddDefaultCharset UTF-8 in the htaccess
What is encoding of a data in MySQL? Php doesn't support raw unicode yet.
精彩评论