我使用的CKEditor用於讓用戶發表評論,用戶也可以把Unicode字符在評論欄中。PHP的DOMDocument不渲染Unicode字符正確
當我提交表單,並檢查$ _ POST [「回覆」]中的Unicode字符顯示得非常好。我也在頁面頂部使用header('Content-type:text/html; charset=utf-8');
但是當我使用PHP DOMDocument處理它時,所有字符都變得不可讀。
$html_unicode = "xyz unicode data";
$html_data = '<body>'.$html_unicode . '</body>';
$dom = new DOMDocument();
$dom->loadHTML($html_data);
$elements = $dom->getElementsByTagName('body');
當我回聲
echo $dom->textContent;
輸出變爲
我怎樣才能得到正確的Unicode字符後面使用PHP的DOMDocument。
這個爲我工作。 我只是這樣做的: $ content = str_replace('','',$ content); – Mahmood