PHP 表单提交 UTF-8
在我的网站上有一个带有简单文本区域的表单,供人们发表评论。问题是有时我会收到 UTF-8 格式的信息,有时会收到 ISO 格式的信息。可以控制吗?
也许我做错了什么,但是浏览器是否有可能更改其发送的数据的编码?
In my website there is a form with a simple textarea for people to post comments. The problem is that sometimes I receive information in UTF-8 and sometimes in ISO. Is it possible to control that?
Maybe I am doing something wrong, but is it possible that the browser changes the codification of the data it sends?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您想确定您接受的字符集,请在表单中进行设置
您可以在此处查看所有可接受的字符集:字符集
If you want to be sure of what character set you are accepting, set it in your form
You can see all the acceptable character sets here: Character Sets
您始终可以强制使用 UTF-8。然后,您可以以 UTF-8 格式发送、接收和存储数据,涵盖大多数人类语言,而无需更改字符集。
You can always force UTF-8. Then you can send, receive, and store data in UTF-8 ad cover most human languages without having to change character set.
但是...在编码之前检查字符串是否已经是 UTF-8。
否则你对其进行双重编码。
或者使用
“所以你不会对字符串进行双重编码”。
But... check before encoding, if string is already UTF-8.
Else you double-encode it.
Or use
So you do not double-encode a string.
我通过更改 php.ini 文件中的 mbstring.http_input = pass 解决了这个问题
I solved this problem by changing mbstring.http_input = pass in my php.ini file
您可以使用 PHP 的 utf8_encode 函数将 $_POST 数据编码为 UTF-8 。
像这样的东西:
You could encode the $_POST data into UTF-8 using PHP's utf8_encode function.
Something like: