简体   繁体   中英

DOMDocument::loadXML(): Input is not proper UTF-8, indicate encoding

Im generating a XML file from database that is formated to utf-8 and creating a XML file, however for a some specific case it is not converting properly and displaying me this message :

DOMDocument::loadXML(): Input is not proper UTF-8, indicate encoding ! Bytes: 0x96 0x20 0x50 0x61 in Entity, line: 1

I have already tried all possible online solutions, going from iconv , trying to do regex but none of these are solving the problem. The mb_encoding returns it is ASCII , which is supposedly UTF-8, even checking the file itself its utf-8.

This is my file start which loads the file path from the database which is the variable $xml_file, all inputs from database are being decoded using utf8_decode.

<?php
$content = utf8_encode(file_get_contents($xml_file));
//$encoding = mb_detect_encoding($content);
//$myXMLString = file_put_contents($xml_file, iconv('WINDOWS-1251', 'UTF-8', file_get_contents($xml_file)));
$xml_doc = new DomDocument();
$xml_doc->formatOutput = true;
$xml_doc->preserveWhiteSpace = false;
$xml_doc->loadXML($content);
?>

This is only happening with some items because other generate correctly, however i can not find any particular difference between them neither a permanent fix for this.

HOW I FIXED :

$content = iconv('UTF-8', 'UTF-8//IGNORE', $content);

设法解决此问题,再次将其转换为UTF-8:

$content = iconv('UTF-8', 'UTF-8//IGNORE', $content);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM