PHP ENV_ 变量:£ 的 UTF-8 编码(磅)
我在“£”字符的编码方面遇到问题。 (问题:当从表单字段 POST '£' 并执行插入时,MySQL 表中不会插入任何内容)。我已经检查了我的 PHP 代码头、服务器、MySQL 上的排序规则/字符集等对 UTF-8 支持的所有内容。
我使用 MAMP 作为我的开发环境(PHP 5.3.5)。
在我的生产服务器(商业主机)(PHP 5.2.6)上一切正常,因此我已经排除了代码的任何问题
但是,我认为我已经找到了罪魁祸首:在比较这两个环境时,我的代码中缺少这一行开发服务器:
_ENV["HTTP_ACCEPT_CHARSET"] ISO-8859-1,utf-8;q=0.7,*;q=0.3
但是,php.ini 中没有任何内容可以更改它。有什么想法,还是我找错了树?
干杯
罗兰
I'm having issues with the encoding of the the '£' character. (Issue: When POSTing '£' from a form field and doing an insert, nothing is inserted in the MySQL table). I've checked everything wrt to UTF-8 support on my PHP code headers, server, collation/char set on MySQL etc.
I'm using MAMP as my dev environment (PHP 5.3.5).
Everything works fine on my production server (commercial host) (PHP 5.2.6) so I've ruled out any issues with my code
However, I think I have tracked down the culprit: When comparing both environments, this line is missing from my dev server:
_ENV["HTTP_ACCEPT_CHARSET"] ISO-8859-1,utf-8;q=0.7,*;q=0.3
However, there is nothing in php.ini I can see to change it. Any ideas, or am I barking up the wrong tree?
Cheers
Roland
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会编写一个简单的测试来检查哪里出了问题。
echo()
从 PHP 中的$_POST
中取出值,并验证浏览器是否正确发送数据以及数据是否被正确解析为 PHP。当您进行此测试时,请确保浏览器已正确检测到字符集。SET NAMES
和表排序规则相同,则不会有任何翻译)继续,以便它将正确存储在表中)。您在问题中的任何地方都没有提到 MySQL 连接(只是“等”)。以防万一您错过了任何内容,请仔细阅读这篇文章 如何避免 PHP 中的字符编码问题
I'd write a simple test to check out where things are going wrong.
echo()
out the value from$_POST
in PHP and verify whether the browser is sending the data correctly and that it's being parsed into PHP correctly. WHen you do this test make sure that the browser has correctly detected the character set.SET NAMES
and the table collation are the same no translation will go on so it'll be stored correctly in the table).You didn't mention the MySQL connection anywhere in your question (just "etc"). Just in case there's anything you've missed have a good look over this article How to Avoid Character Encoding Problems in PHP