有没有PHP功能来解决这个问题? [英] Is there a PHP function to fix this?

查看:104
本文介绍了有没有PHP功能来解决这个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何解决这个问题?

解决方案

你正在遇到的是数据被写入一个编码的结果,并被解释为另一个。您需要确保您要求输入的格式与您期望的格式相同。我建议您一直遵循UTF-8,除非您需要避免多字节字符,否则你可能想要看强制ASCII。



确保你在告诉PHP在内部使用UTF-8:

  ini_set('default_charset','UTF-8'); 

并确保您正在告诉浏览器期望UTF-8编码的文本,无论是在标题...

 标题(Content-Type:text / html; charset = UTF-8); 

...和您的元标记(下面是html5)...

 < meta charset =utf-8> 

设置此选项将告知浏览器在提交表单时向您发送UTF-8编码的内容,它会将您发回的结果解释为UTF-8。



您还应确保数据库存储和连接编码都是UTF-8。通常只要它只是一个愚蠢的数据存储(即它不会以任何方式操纵或解释数据),这并不重要,但是更好的是让它以后再遇到问题。 / p>

"“Excuse me, I hope this isn’t weird or anything,"

How can I fix the encoding on this?

解决方案

What you're running into is the result of the data being written in one encoding, and interpreted as being another. You need to make sure that you're requesting input to be in the same format that you're expecting it to be in. I recommend just sticking with UTF-8 the whole way through unless you need to avoid multibyte characters, in which case you might want to look at forcing ASCII.

Make sure you're telling PHP to use UTF-8 internally:

ini_set('default_charset', 'UTF-8');

And make sure that you are telling the browser to expect UTF-8 encoded text, both in headers…

header("Content-Type:text/html; charset=UTF-8");

…and in your meta tags (html5 below)…

<meta charset="utf-8">

Setting this will tell the browser to sent UTF-8 encoded content to you when a form is submitted, and it'll interpret the results you send back as UTF-8 as well.

You should also make sure both your database storage and connection encoding are in UTF-8 as well. Usually as long as it is just a dumb data store (i.e. it won't be manipulating or interpreting the data in any way) it doesn't matter, but it's better to have it all right than run into problems with it later.

这篇关于有没有PHP功能来解决这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆