I have following code with which i am writing the xml files in php,But when i run this code,I get following error
SimpleXMLElement::asXML(): string is not in UTF-8
Code for generating xml is as follows
<?php
//Create Database connection
$mysqli = new mysqli('localhost', 'user', 'pass', 'dbnam');
if(mysqli_connect_errno()) {
echo "Connection Failed: " . mysqli_connect_errno();
}
$query='select Siteurl from tablename order by colname2 desc ';
$result = mysqli_query($mysqli,$query);
//Create SimpleXMLElement object
$xml = new SimpleXMLElement('<urls/>');
//Add each column value a node of the XML object
while($row = mysqli_fetch_array($result)) {
$mydata = $xml->addChild('url');
$mydata->loc=$row['Siteurl'];
}
mysqli_close($mysqli);
//Create the XML file
$fp = fopen("sitemaps/sitemap2.xml","wb");
//Write the XML nodes
fwrite($fp,$xml->asXML());
//Close the database connection
fclose($fp);
?>
How can i correct the error guys.Please help me