简体   繁体   English

mysql_real_escape_string和撇号问题

[英]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 ’ 因此我一直在使用mysql_real_escape_string将数据插入到数据库中...但是,当我这样做时,它会用符号’替换所有的撇号

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. 因为在UTF-8中, ' (U + 2019)用0xE28099编码。 And that represents the characters â (0xE2), (0x80), and (0x99) in Windows-1252 . Windows-1252中 ,它表示字符â (0xE2), (0x80)和 (0x99)。

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. 因此,您似乎只是忘记了正确指定输出字符编码,因此浏览器改为使用其默认字符编码Windows-1252。

在您的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. 在您的PHP应用程序中,您可以使用以下两行来指定它。

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. 这会将您的应用程序设置为使用UTF-8字符集,您必须确保该字符集与数据库的排序规则相匹配,然后问题才会消失。

You can programatically change the database character set with the mysql_set_charset function. 您可以使用mysql_set_charset函数以编程方式更改数据库字符集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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