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

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

问题描述

有没有办法修复通过phpquery::newDocument运行这个html标记后显示不正确的字符?在使用 phpquery 创建新文档后,原始文档中的 -Classics with modern Woman- 周围有预定的双引号.

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 without BOM 编码保存页面.
  2. 在脚本顶部添加此标题:

  1. You need to save the page with UTF-8 without BOM encoding.
  2. Add this header on top of your script:

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

:如何在没有 BOM 的情况下将文件另存为 UTF-8 :

根据 OP 要求,您可以在 Windows 上执行以下操作:

On OP request, here's how you can do on Windows:

  1. 下载Notepad++.这是一个很棒的文本编辑器,您应该使用它.
  2. 安装它.
  3. 在 Notepad++ 中打开包含此代码的 PHP 脚本.您正在执行所有编码的页面.是的,您计算机上的那个文件.
  4. 在 Notepad++ 中,从顶部的编码菜单中,选择不带 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天全站免登陆