UTF-8 在 HTML 表单中不起作用
我有这个表格:
<form method="post" enctype="multipart/form-data" accept-charset="UTF-8">
但是当我提交 é 字符时,它会变成 é.
But when I submit an é character, it turns it into é.
为什么这不起作用?是的,MySQL 数据库已正确设置所有字符集.(数据库,表格.)如果我用 Navicat 手动将它放入数据库,它会在网页上正常显示.
Why doesn't this work? Yes, the MySQL database has all the character-sets set up correctly. (Database, tables.) If I manually put it in the database with Navicat it shows up fine on the webpage.
另外,我尝试了元标记,设置了内容类型标头,但没有成功.
Also, I have tried the metatag, setting the content-type header, without success.
推荐答案
在你的 HTML 中,添加这个元标记:
In your HTML, add this meta tag:
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
还要在脚本顶部添加此 PHP 标头:
Also add this PHP header at top of the script:
header("Content-Type: text/html;charset=UTF-8");
:
另外一个技巧是将文件保存为 UTF-8 without BOM
编码.您可以使用 Notepad++ 或任何不错的编辑器来执行此操作.
One more tip is to save the file as UTF-8 without BOM
encoding. You can use Notepad++ or any decent editor to do that.
相关文章