php: using DomDocument whenever I try to write UTF-8 it writes the hexadecimal notation of it

前端 未结 6 951
清歌不尽
清歌不尽 2020-11-27 21:41

When I try to write UTF-8 Strings into an XML file using DomDocument it actually writes the hexadecimal notation of the string instead of the string itself.

for exam

6条回答
  •  庸人自扰
    2020-11-27 22:20

    To the point answer is:

    When your function starts, right after you get the content, do this:

    $content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8');
    

    And then start the new document etc. Check this as example:

    if ( empty( $content ) ) {
        return false;
    }
    $doc = new DOMDocument('1.0', 'utf-8');
    libxml_use_internal_errors(true);
    $doc->LoadHTML($content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
    

    Then do whatever you were intending to do with your code.

提交回复
热议问题