N
N
NkDev2021-02-10 16:38:54
PHP
NkDev, 2021-02-10 16:38:54

How to return Russian text when using DOMDocument library?

There is this code:

$html = 'hello!';

$document = new DOMDocument();

$document->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
 
 echo $document->saveHTML();


The output is coding:
<html><body><p>&#1044;&#1086;&#1073;&#1088;&#1099;&#1081; &#1076;&#1077;&#1085;&#1100;!</p></body></html>


Please tell me! How to return Russian text?

sandbox.onlinephpfunctions.com/code/e56788edb63b5d...

Thanks!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tim, 2021-02-10
@NkDev

sandbox.onlinephpfunctions.com/code/d9eca979b138c9...

<?php
$html = 'Добрый день!';
$document = new DOMDocument();
$document->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
echo $document->saveHTML((new \DOMXPath($document))->query('/')->item(0));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question