$dom = new DomDocument(); $dom->loadHTML($html); echo $dom->saveHTML(); The output is obracadabra. I tried through iconv, the same thing. How to make sure that both Russian and Latin characters are displayed correctly?
$dom = new DomDocument(); $dom->loadHTML($html); echo $dom->saveHTML(); The output is obracadabra. I tried through iconv, the same thing. How to make sure that both Russian and Latin characters are displayed correctly?
You can try to do this before working with a DomDocument:
$string = mb_convert_encoding($string, 'HTML-ENTITIES', "UTF-8") It helped me once.
You must specify the encoding meta tags in the HTML itself:
$dom = new DOMDocument($html); $dom->loadHTML($html); $nodeHead=$dom->createElement("head"); $nodeMeta=$dom->createElement('meta'); $dom->insertBefore($nodeHead, $dom->firstChild); $nodeMeta->setAttribute ("http-equiv","Character"); $nodeMeta->setAttribute ("content","ISO-8859-1"); $nodeHead->appendChild($nodeMeta); $nodeMeta=$dom->createElement('meta'); $nodeMeta->setAttribute ("http-equiv","Content-Type"); $nodeMeta->setAttribute ("content","text/html; charset=ISO-8859-1"); $nodeHead->appendChild($nodeMeta); echo $dom->saveHTML(); Source: https://ru.stackoverflow.com/questions/514089/
All Articles