I'm parsing an XML-Feed which contains UTF-8 encoded characters like this:
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<value>Ströng</value>
</root>
Parsing this file with returns a malformed Ströng
:
$file = file_get_contents($path);
print_r($file);
Using $xml = simplexml_load_file($path);
yields the same result.
Now I've tried to use the utf8_encode()
function to correct the character encoding like that:
$file = utf8_encode(file_get_contents($path));
print_r($file);
But now the content gets even worse malformed: Ströng
. Why is that?
How to parse XML in UTF8 format correctly?
Update:
mb_detect_encoding($file)
returns: UTF-8
and utf8_decode()
returns Str?ng
.
Everything seems correct so far but it isn't?