使用 php 修复 html 文档上错误显示的编码
有没有办法修复通过 phpquery::newDocument 运行此 html 标记后显示不正确的字符?原始文档中的 -Classics with Modern Woman- 周围有预定的双引号,在使用 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);
原始输出: 曼谷的史密斯先生庆祝“经典与现代女性”。
新文件输出:曼谷的史密斯先生庆祝“经典与现代女性”。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
UTF-8 without BOM
编码保存页面。将此标头添加到脚本顶部:
header("Content-Type: text/html; charset=UTF-8");
[编辑]:如何将文件另存为不带 BOM 的 UTF-8 :
根据 OP 请求,您可以执行以下操作Windows:
UTF-8 without BOM
encoding.Add this header on top of your script:
header("Content-Type: text/html; charset=UTF-8");
[EDIT]: How to Save Files as UTF-8 without BOM :
On OP request, here's how you can do on Windows:
我遇到了同样的问题,但是当我将
第一行添加到
最后时,它似乎正在工作
i had the same problem but when i added
to first line
to the end it seem to be working
您可以在
元素中找到此内容:
下一课程是使用 HTML 实体来显示这些字符。
You have this in the
<head>
element:The next course would be to use HTML entities to display these characters.
我使用 phpQuery 类遇到了同样的问题。问题如上所述,在投票最高的答案中 - 脚本文件保存为带有 BOM 的 UTF8。
由于我没有机会在 mac osX 上获取 notepad++,
因此我像这样准备的每个输出
utf8_decode()
BOM 都是针对 MS-windows 的。
I had same problem using phpQuery class. Problem IS as mentioned above, in top voted answer - script file is saved as UTF8-with BOM.
As i had no no chance getting notepad++ on mac osX,
every output i prepared like this
utf8_decode()
BOM is meant for MS-windows.