使用php修复html文档上的错误显示编码 [英] Fix incorrectly displayed encoding on an html document with php
问题描述
通过phpquery :: newDocument运行此html标记后,是否有办法修复显示不正确的字符?在原始文档中,古典主义与现代女性相似,有双引号,最终在使用phpquery创建新文档后最终显示不正确。
Is there a way to fix the characters that display improperly after running this html markup through phpquery::newDocument? There are slated double quotes around -Classics with modern Woman- in the original document that end up displaying improperly after creating the new doc with phpquery.
//Original document is UTF-8 encoded
$raw_html = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><p>Mr. Smith of Bangkok celebrated the "Classics with modern Woman".</p></body></html>';
print($raw_html);
$aNew_document = phpQuery::newDocument($raw_html);
print($aNew_document);
原创输出:
曼谷史密斯先生庆祝了现代女性经典。
Original Output: Mr. Smith of Bangkok celebrated the "Classics with modern Woman".
新文件输出:曼谷史密斯先生与现代女性庆祝 经典。
New Document Output: Mr. Smith of Bangkok celebrated the �Classics with modern Woman.
推荐答案
- 您需要使用
UTF-8而不使用BOM
编码来保存页面。 -
将此标题添加到脚本之上:
- You need to save the page with
UTF-8 without BOM
encoding. Add this header on top of your script:
标题(Content-Type :text / html; charset = UTF-8);
:如何将文件保存为没有BOM的UTF-8:
在OP请求中,您可以在Windows上执行以下操作:
On OP request, here's how you can do on Windows:
- 下载记事本++ 。这是一个你应该使用的真棒文本编辑器。
- 安装它。
- 在包含该代码的记事本++中打开PHP脚本。你正在做所有编码的页面。是的,您的电脑上的该文件。
- 在记事本++中,从顶部的编码菜单中选择转换为不带BOM的UTF-8。
- 通过FTP或任何您使用的方式上传到您的网络服务器。
- 现在,运行该脚本。
<
- Download Notepad++. It is an awesome text-editor that you should be using.
- Install it.
- open the PHP script in Notepad++ that contains this code. The page where you are doing all the coding. Yes, that file on your computer.
- In Notepad++, from the Encoding menu at the top, select "Convert to UTF-8 without BOM".
- Save the file.
- Upload to your webserver by FTP or whatever you use.
- Now, run that script.
这篇关于使用php修复html文档上的错误显示编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!