简体   繁体   English

PHP网站地图生成器标签

[英]PHP sitemap generator strips tag

This is my code to create xml sitemap. 这是我创建xml网站地图的代码。 But problem is that when it creates xml file it doesn't include <?xml version="1.0" encoding="UTF-8"?> . 但是问题在于,当它创建xml文件时,它不包含<?xml version="1.0" encoding="UTF-8"?> It includes every tag wirteen in my function except that one. 它包括我的函数中除wirteen之外的所有标记。

   // 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. 我所要做的就是在浏览器中查看该xml文件的源代码,并且标记在那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM