1

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 encoding. There must be a way to show it right because phpMyAdmin does it

4
  • And it comes out right in FF? Or any other browser? I can save it to a php variable and echo it. Viewing in Chrome - worked. Commented May 26, 2011 at 6:05
  • I get the question mark on FF Commented May 26, 2011 at 6:11
  • Oh now I see what you are saying. OK I tried the same and it also worked. So now I'm more confused. Commented May 26, 2011 at 6:14
  • I really think the problem is with MySQL, because I can properly echo the character if I do this: echo "•";. Commented May 26, 2011 at 6:35

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

Should I do that before or after mysql_select_db?
I am doing it after db selection.
I think your code is for MySQL lite or something. I tried mysql_query('SET NAMES \'utf8\''); but it looks even messier.
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'")
In Firefox open Page Information (right click in Page -> Page Information) and add a screenshot of the appearing window to your question. My database is our production database, a fully grown up-to-date MySQL
0

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

7 Comments

I just tried utf8_encode and at least the ugly chars disappear, but is still not what I want. My page's char encoding is utf8, same as phpMyAdmin. There must be a way to show it right because phpMyAdmin does it.
Are you sure is your page utf8?, go to browser then check encoding see what is selected on your page. sometimes settings of the server make it ignore what you set for encoding in the html. beside what's the encoding of the database and the table and the field. make sure they are all utf8.
OK I just saw in Fiddler. My page is "Content-Type: text/html", but phpMyAdmin is "Content-Type: text/html; charset=utf-8". Wonder if that's the problem. Can you change this from PHP code?
How about you try add AddDefaultCharset UTF-8 in the htaccess? and see if it works for you.
@jsoldi: Try adding <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> to your <head></head> section of your page
|
0

What is encoding of a data in MySQL? Php doesn't support raw unicode yet.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.