使用php修复html文档上的错误显示编码 [英] Fix incorrectly displayed encoding on an html document with php

查看:91
本文介绍了使用php修复html文档上的错误显示编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过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.

推荐答案


  1. 您需要使用 UTF-8而不使用BOM 编码来保存页面。

  2. 将此标题添加到脚本之上:

  1. You need to save the page with UTF-8 without BOM encoding.
  2. 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:


  1. 下载记事本++ 。这是一个你应该使用的真棒文本编辑器。

  2. 安装它。

  3. 在包含该代码的记事本++中打开PHP脚本。你正在做所有编码的页面。是的,您的电脑上的该文件。

  4. 在记事本++中,从顶​​部的编码菜单中选择转换为不带BOM的UTF-8。

  5. <
  6. 通过FTP或任何您使用的方式上传到您的网络服务器。

  7. 现在,运行该脚本。

  1. Download Notepad++. It is an awesome text-editor that you should be using.
  2. Install it.
  3. 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.
  4. In Notepad++, from the Encoding menu at the top, select "Convert to UTF-8 without BOM".
  5. Save the file.
  6. Upload to your webserver by FTP or whatever you use.
  7. Now, run that script.

这篇关于使用php修复html文档上的错误显示编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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