Debiprasad
Debiprasad

Reputation: 6183

Character encoding issue in PHP and MySQL

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 saves data as , but when I run the query in my PHP code, then it does not work in the way I want.

Upvotes: 1

Views: 864

Answers (3)

kiewic
kiewic

Reputation: 16450

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; 

Upvotes: 0

erenon
erenon

Reputation: 19158

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

Upvotes: 1

hsz
hsz

Reputation: 152304

Maybe phpMyAdmin engine escapes long dash to normal dash ?

Upvotes: 0

Related Questions