views:

290

answers:

3

When I run a query directly in MySQL using phpMyAdmin it allows (long dash, not normal -), but when I run this query from my PHP code, it turns them to –.

If you encode – it'll come %E2%80%93 (in JavaScript). %E2 becomes â, %80 becomes and %93 becomes . I don't understand when I run the query in phpMyAdmin it shaves data as , but when I run the query in my PHP code, then it does not work in the way I want.

A: 

Maybe phpMyAdmin engine escapes long dash to normal dash ?

hsz
No, it does not escapes long dash to normal dash.
Debiprasad
A: 

Which character encoding do you use in your table? After connecting to the DB in php try to run this:

mysql_query('SET NAMES utf8'); //if you use utf-8
erenon
Do you mean Collation of the filed? It's "latin1_swedish_ci".BTW, your suggestion worked. Thank You very much!
Debiprasad
@Debiprasad: Unless you are swdish, you should shwitch to utf-8. It makes life easier.
erenon
Even if you *are* swedish, a switch to UTF-8 won't hurt. :)
Pekka
So you guys suggest to use this:DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ciThank you!
Debiprasad
I modified my database, table and column to utf8, also removed mysql_query('SET NAMES utf8'); - now I can see now old issue.Earlier those are in "latin1_swedish_ci" and I added mysql_query('SET NAMES utf8'); to my code. Here I was not experiecing the issue.I need to learn more on this and will update about this here.
Debiprasad
A: 

Probably you are missing to put the met tag on your HTML, have you write the next line in the head of your HTML document?

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

Otherwise, the browser interprets it as ISO-8859-1.

You should use the same encoding everywhere, on your database, on your connection and on your html document.

For ensure you have a utf-8 table, run the next statement, and check it says CHARSET=utf8 almost at the end.

 SHOW CREATE TABLE tableName;
Kiewic
No, this is not the problem. Thank you.
Debiprasad
The query returns: DEFAULT CHARSET=latin1
Debiprasad