PHP DOMDocument is not rendering Unicode Characters Properly

domdocument, php, unicode

Solution

Thank God I got the Solution By Just Replacing

$html_data = '<body>'.$html_unicode . '</body>';

with

$html_data = '<head><meta http-equiv="Content-Type" 
content="text/html; charset=utf-8">
</head><body>' . $html_unicode . '</body>';

Problem

I am using CKEditor for letting the user to post comments, user can also put the unicode characters in the comment box. When I submit the Form and Check the $_POST["reply"], the unicode characters are shown very well. I have also used `header('Content-type:text/html; charset=utf-8');` at the top of the page But When I process it using PHP DOMDocument, all the characters become unreadable. ``` $html_unicode = "xyz unicode data"; $html_data = '<body>'.$html_unicode . '</body>'; $dom = new DOMDocument(); $dom->loadHTML($html_data ); $elements = $dom->getElementsByTagName('body'); ``` When I echo ``` echo $dom->textContent; ``` The Output becomes ``` §Ø³ÙبÙÙ ÙÙÚº ØºØ±ÙØ¨ ک٠آÙÛ ÙÛÙ ``` How Can I get the proper unicode characters back using PHP DOMDocument.

Original source