問題描述
有沒有辦法修復通過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.
推薦答案
- 您需要使用
UTF-8 without BOM
編碼保存頁面. 在腳本頂部添加此標題:
- You need to save the page with
UTF-8 without BOM
encoding. 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:
- 下載Notepad++.這是一個很棒的文本編輯器,您應該使用它.
- 安裝它.
- 在 Notepad++ 中打開包含此代碼的 PHP 腳本.您正在執行所有編碼的頁面.是的,您計算機上的那個文件.
- 在 Notepad++ 中,從頂部的編碼菜單中,選擇不帶 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 文檔上顯示不正確的編碼的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!