正确的字符编码,以显示“& acirc;€”? [英] Proper character encoding to display "”"?

查看:183
本文介绍了正确的字符编码,以显示“& acirc;€”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些令人讨厌的字符编码问题,我只是不能弄清楚。

I'm having some nasty character encoding problems that I just can't figure out.

基本上,我的屏幕刮掉一些网站的HTML PHP,然后通过PHP的DOMDocument运行它来改变一些URL等等,当它完成时,它输出HTML与一些奇怪的东西。例如:应该有结束报价,它会输出& acirc;€

Essentially, I'm screen scraping some HTML off of a site using PHP, then running it through PHP's DOMDocument to change out some URL's, etc., and when it's done, it outputs HTML with some weird things. Ex: where there should be an end quote, it puts out ”

我将页面的元标记设置为 utf-8 ,但是& acirc;€& ;#157; 字符在网站上显示为â€。我不知道我只是不理解字符编码,或什么。

I have the page's meta tag for charset set to utf-8 but then the ” characters are showing up as †on the site. I'm not sure if I just don't understand character encoding, or what.

有什么建议,最好的方法来解决这个问题?

Any suggestions on the best way to resolve this? Something client side with a meta tag, or some kind of server-side PHP conversion?

推荐答案

有时在HTML或者HTML中设置字符集响应头是不够的。如果您的服务器上没有为UTF-8设置一切,您的文本可能会在某处不正确地转换。您可能需要在其配置文件中为Apache和PHP启用UTF-8编码。 (如果您不使用Apache,请尝试跳过此步骤。)

Sometimes setting the charset in HTML or the response header isn't enough. If everything isn't setup for UTF-8 on your server, your text may get incorrectly converted somewhere along the way. You may need to enable UTF-8 encoding for both Apache and PHP right in their config files. (If you're not using Apache, try skipping that step.)

通过在结尾添加以下行,编辑 charset.conf (理想的)或 httpd.conf 文件:

Edit either your charset.conf (ideal), or httpd.conf file, by adding this line to the end:

AddDefaultCharset utf-8

无法访问Apache的配置文件,则可以使用相同的代码在HTML的根目录中创建一个 .htaccess 文件。)

(If you don't have access to Apache's config files, you can create a ".htaccess" file in your HTML's root directory with that same code.)

编辑您的php.ini文件,搜索 default_charset ,并将其更改为:

Edit your php.ini file, searching for "default_charset", and change it to:

default_charset = "utf-8"



重新启动Apache:



根据您的服务器类型,此命令可通过命令行执行:

Restart Apache:

Depending on your server type, this command may do the trick via command line:

sudo service apache2 restart

这篇关于正确的字符编码,以显示“& acirc;€”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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