简体   繁体   中英

mysql_real_escape_string and apostrophe problem

so I've been using mysql_real_escape_string to insert data into my database...but then when I do that it replaces all apostrophes with the symbol ’

so instead of display it's, it's displaying it’s.......

is there a way to reconvert those ’'s into apostrophes when I read back from the database?

This is some character encoding issue in some way.

Because in UTF-8, ' (U+2019) is encoded with 0xE28099. And that represents the characters â (0xE2), (0x80), and (0x99) in Windows-1252 .

So it seems that you just forgot to specify your output character encoding properly so that the browser uses its default character encoding Windows-1252 instead.

在您的PHP中将mysql_set_charset应用于UTF-8。

Ensure your database and application are using the same character encoding.

In binary, ' is identical in value to ’ , so you need to ensure the encoding is set the same.

In your PHP application, you can specify this with the following two lines.

define(‘DB_CHARSET’, ‘utf8′);
define(‘DB_COLLATE’, ”);

This sets your application to use UTF-8 character set, which you must ensure matches your database's collation, then your problem will go away.

You can programatically change the database character set with the mysql_set_charset function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM