Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $doc = new DOMDocument('1.0', 'iso-8859-1');
- $doc->load($xmlPath);
- $myXMLString = file_get_contents($xmlPath);
- $myXMLString = utf8_decode($myXMLString);
- $doc = new DOMDocument('1.0', 'iso-8859-1');
- $doc->loadXML($myXMLString);
- <?php
- // german Umlaut ä in latin1 = 0xE4
- $xml = '<foo>'.chr(0xE4).'</foo>';
- $doc = new DOMDocument;
- $b = $doc->loadxml($xml);
- echo 'with doc->recover=false(default) : ', ($b) ? 'success':'failed', "n";
- $doc = new DOMDocument;
- $doc->recover = true;
- $b = $doc->loadxml($xml);
- echo 'with doc->recover=true : ', ($b) ? 'success':'failed', "n";
- Warning: DOMDocument::loadXML(): Input is not proper UTF-8, indicate encoding !
- Bytes: 0xE4 0x3C 0x2F 0x66 in Entity, line: 1 in test.php on line 6
- with doc->recover=false(default) : failed
- Warning: DOMDocument::loadXML(): Input is not proper UTF-8, indicate encoding !
- Bytes: 0xE4 0x3C 0x2F 0x66 in Entity, line: 1 in test.php on line 11
- with doc->recover=true : success
- <?php
- $xml = sprintf('<foo>
- <ae>%s</ae>
- <oe>%s</oe>
- &
- </foo>', chr(0xE4),chr(0xF6));
- libxml_use_internal_errors(true);
- $doc = new DOMDocument;
- $doc->recover = true;
- libxml_clear_errors();
- $b = $doc->loadxml($xml);
- $invalidCharFound = false;
- foreach(libxml_get_errors() as $error) {
- if ( 9==$error->code && !$invalidCharFound ) {
- $invalidCharFound = true;
- echo "found invalid char, possibly harmlessn";
- }
- else {
- echo "hm, that's probably more severe: ", $error->message, "n";
- }
- }
Add Comment
Please, Sign In to add comment