0

So, I'm trying to echo an xml file in php as follows:

<?php
header("Content-type: text/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo "<root>
";

$servername = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "tiles";
$conn = mysqli_connect($servername, $dbuser, $dbpass, $dbname);
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT * FROM ajrpg_spritedata";

if ($result=mysqli_query($conn,$sql)){
    while ($row=mysqli_fetch_row($result)){
        echo '<botass>
    <arr>data</arr>
    <ID>' . $row[0] . '</ID>
    <data>7A8B20A6B8C3B16AB6C8D3ĊČ3ďC5D8E3ĔĖ1ąBCD15ĞĠB9ęĦĝğCĈĭ21EDıĀĤD22ĶıĎĺ23ľB5ij4ń4ijĨķBĘŁ6ń2ij7ńĭ9Ķ1ŕōŗřĝķ2ĺŘĮľšĥE2CőŤŠĺŨŪĶőũŃDūıĭşŲCĽDśıœĺĨ2DŨŽĶşıŏĚDĨ7DţıŊŁňōƒĥŌŚƅıņĺƔ1ň4ōŀĥƔƘ0ƚĐęěEě1żĿijƯƩƝřŲōƜƗřƂƢęƃƔƔŘİƳŧơCơŕěưƁEıCƮĩƛƱƅŅijŴǑăĔĶţĝƃıĢAżşŕ1ĬūŃ</data>
    <data>' . $row[1] . '</data>
';
    }
    mysqli_free_result($result);
}

mysqli_close($conn);
echo "</botass>
</root>";
?>

The first data element is copy/pasted unicode just to see if it actually shows up right if it gets the right data, the second one is fetched from a MySQL database, and it's all saved as an utf-8 text file.

The database consists of 2 fields, ID and the unicode data string stored in a text field with utf8mb4_bin format in a table with utf8mb4_bin formatting like this:

enter image description here

and still, it just results in this:

<?xml version="1.0" encoding="UTF-8"?><root>
<botass>
    <arr>data</arr>
    <ID>1</ID>
    <data>7A8B20A6B8C3B16AB6C8D3ĊČ3ďC5D8E3ĔĖ1ąBCD15ĞĠB9ęĦĝğCĈĭ21EDıĀĤD22ĶıĎĺ23ľB5ij4ń4ijĨķBĘŁ6ń2ij7ńĭ9Ķ1ŕōŗřĝķ2ĺŘĮľšĥE2CőŤŠĺŨŪĶőũŃDūıĭşŲCĽDśıœĺĨ2DŨŽĶşıŏĚDĨ7DţıŊŁňōƒĥŌŚƅıņĺƔ1ň4ōŀĥƔƘ0ƚĐęěEě1żĿijƯƩƝřŲōƜƗřƂƢęƃƔƔŘİƳŧơCơŕěưƁEıCƮĩƛƱƅŅijŴǑăĔĶţĝƃıĢAżşŕ1ĬūŃ</data>
    <data>7A8B20A6B8C3B16AB6C8D3??3?C5D8E3??1?BCD15??B9????C??21ED???D22????23?B5?4?4???B??6?2?7??9?1??????2????

As well as an error message about encoding error.

what encoding setting am I missing here?

Daniel Bengtsson
  • 302
  • 1
  • 3
  • 12

0 Answers0