我必须通过php文件读取txt。此文件包含一些普通符号,因此可能包含此类符号:
€ é ò à ° % etc我用file_get_contents读取php中的内容,并将它们转换为插入到SQL数据库中。
$contFile = file_get_contents($pathFile);
$testoCommento = htmlspecialchars($contFile,ENT_QUOTES);
$testoCommento = addslashes($testoCommento);现在,如果我有这样的文本,例如:"l'attesa �é cruciale fino a quando il topo non viene morso dall'�€" in the database,我有这样的内容:
l'attesa è cruciale fino a quando il topo non veniene morso dall'€当我从数据库获取数据时,我使用php函数来解码html实体。
$descrizione = htmlspecialchars_decode($risultato['descrizione'],ENT_QUOTES);
$descrizione = addslashes($descrizione);现在,我使用jasvascript和AJAX来获取表格内容并在浏览器中显示为HTML页面,而不是获取正确的文本(欧元,è)我使用的是正方形符号。我认为字符集的代码/解码有一些混乱,但从来没有弄清楚。
SQL‘表为"utf8_unicode_ci“格式,列为"utf8_general_ci”。页面的内容类型为
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />谢谢你的帮助!
发布于 2010-07-22 21:44:03
addslashes()与Unicode不兼容,您应该使用不同的方法来转义字符串中的引号,或者(这会更好)切换到使用准备好的语句,而不是将SQL查询构造为字符串。
有关详细信息,请访问:http://eleves.ec-lille.fr/~couprieg/post/Bypass-addslashes-with-UTF-8-characters
https://stackoverflow.com/questions/3014509
复制相似问题