我必须通过文件php读取txt。这个文件包含一些正常,所以可能包含这种符号:
€ é ò à ° % etc
我使用file_get_contents读取php中的内容,并将这些内容转换为SQL数据库中的inserenting。
$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'�€"
在数据库中我有这个:
l'attesa è cruciale fino a quando il topo non veniene morso dall'€
当我从数据库获取数据时,我使用php函数解码html entites
$descrizione = htmlspecialchars_decode($risultato['descrizione'],ENT_QUOTES);
$descrizione = addslashes($descrizione);
现在我使用jasvascript和AJAX来获取表格内容并显示到HTML页面 在浏览器中而不是获取正确的文本(€,è)我有方形符号。 我认为charset代码/解码有些混乱,但从未弄清楚。
SQL'表格为“utf8_unicode_ci”格式,列为“utf8_general_ci”。 页面的内容类型是
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
谢谢你的帮助!
答案 0 :(得分:0)
addslashes()与Unicode不兼容,你应该使用不同的方法来转义字符串中的引号,或者(这会更好)切换到使用预准备语句而不是将SQL查询构造为字符串。 / p>
您可以在以下网址找到更多详情:http://eleves.ec-lille.fr/~couprieg/post/Bypass-addslashes-with-UTF-8-characters