PHP DOMDocument loadHTML not encoding UTF-8 correctly

后端 未结 13 1722
梦如初夏
梦如初夏 2020-11-22 15:11

I\'m trying to parse some HTML using DOMDocument, but when I do, I suddenly lose my encoding (at least that is how it appears to me).

$profile = \"

        
13条回答
  •  轮回少年
    2020-11-22 15:23

    I am using php 7.3.8 on a manjaro and I was working with Persian content. This solved my problem:

    $html = 'hi

    سلام

    の家庭に、9 ☆'; $doc = new DOMDocument('1.0', 'UTF-8'); $doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8')); print $doc->saveHTML($doc->documentElement) . PHP_EOL . PHP_EOL;

提交回复
热议问题