Chinese characters are garbled when PHP DOMDocument saves xml.
Solution to the problem that Chinese characters appear garbled when PHP DOMDocument saves xml: 1. Specify the encoding when loading HTML, the code is [$doc->loadHTML('']; 2. Use iconv to output The characters are re-converted.
##Solution to the problem that Chinese characters appear garbled when PHP DOMDocument saves xml:
The first method: Specify the encoding when loading HTML. The following code is quoted from the reply in the official php.net document$doc = new DOMDocument(); $doc->loadHTML('<?xml encoding="UTF-8">' . $html); // dirty fix foreach ($doc->childNodes as $item) if ($item->nodeType == XML_PI_NODE) $doc->removeChild($item); // remove hack $doc->encoding = 'UTF-8'; // insert properThe second method is to re-convert the output characters through iconv. The code is as follows:
echo iconv("UTF-8", "GB18030//TRANSLIT", $dom->saveXML($n) );
Related video recommendations:
The above is the detailed content of Chinese characters are garbled when PHP DOMDocument saves xml.. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1
Easy-to-use and free code editor

WebStorm Mac version
Useful JavaScript development tools