i am trying to generate xml document with the help of php but i am getting some issue. Please help Shows this error: This page contains the following errors: error on line 1 at column 1: Document is empty Below is a rendering of the page up to the first error.
<?php
$con = mysqli_connect('localhost', 'ypnepalc_user','ypnepal@123', 'ypnepalc_main');
$listings = $con->query("SELECT url FROM listings");
$array_listings =[];
if($listings -> num_rows > 0) {
while ($row = $listings -> fetch_assoc()) {
$array_listings[] = $row['url'];
}
}
$data_xml= 'urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9';
$static_url = [
'https://ypnepal.com.np',
];
foreach ($array_listings as $url) {
$date = ('c');
$pr = '0.80';
if($url == 'https://ypnepal.com.np') $pr='1.00';
$data_xml .="
<url>
<loc>$url</loc>
<lastmod>$date</lastmod>
<priority>$pr</priority>
</url>
";
}
$data_xml .= '</urlset>';
$file = fopen ('sitemap.xml', 'w');
fwrite($file, $data_xml);