This is my code to create xml sitemap. But problem is that when it creates xml file it doesn't include <?xml version="1.0" encoding="UTF-8"?>
. It includes every tag wirteen in my function except that one.
// this variable will contain the XML sitemap that will be saved in $xmlfile
$xmlsitemap = '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
$xmlfile=array('sitemapinternal.xml');
internalSiteMap($xmlsitemap, $xmlfile[0]);
//za one vijesti koje su unutar mog sajta /vijesti/kategorija/jSFh8
function internalSitemap($xmlsitemap, $xmlfile)
{
// Define and perform the SQL SELECT query
$sql = "SELECT * FROM table";
$result = $mysqli->query($sql);
// If the SQL query is succesfully performed ($result not false)
if($result !== false)
{
// Parse the result set, and add the URL in the XML structure
while($red=$result->fetch_assoc())
{
$xmlsitemap .=
'<url>
<loc>http://www.example.com</loc>
<priority>0.5</priority>
<changefreq>yearly</changefreq>
<lastmod>'.date('Y-m-d', strtotime($red['datum'])).'</lastmod>
</url>';
}
}
$xmlsitemap .= '</urlset>';
file_put_contents($xmlfile, $xmlsitemap); // saves the sitemap on server
}
So stupid of me. All I should do is to view source of that xml file in browser and tag was there.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.