问题:
db中插入åöö的输入。该文件是UTF-8,没有BOM,表中的注释有utf8_general_ci coallition。
代码:
<?php
if($_POST['comment']!=''){
$comment=addcslashes($_POST['comment'], "\x00\n\r\'\x1a\x3c\x3e\x25");
if($kommentar!=''){
mysql_query("INSERT INTO comments (comment) VALUES ('$comment')") or die(mysql_error());
}
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="sv">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<body>
//Form
</body>
背景:
早些时候我在$ _POST ['comment']上执行了htmlentities;在插入db之前,直接输出,哪个工作正常。然后我想进行最佳实践并在输出上输入原始数据(只是清洁)和其他数据(或类似)。但后来我发现了åäö不作为åäö输入,而是作为åö输入。 Heeeelp:)
答案 0 :(得分:2)
您可能需要将连接的排序规则设置为UTF-8,默认情况下为iso-8859-1。 尝试
mysql_set_charset("utf8");
连接数据库后。