如何在 sitemap.xml 上打印或显示 sitemap.php 数据?

How to print or show sitemap.php data on sitemap.xml?

这是我的动态站点地图 sitemap.php 文件中的代码,但我想在“[= 上打印或显示整个页面数据24=]" 因为 Google 始终考虑 sitemap.xml 对于 sitemap.This 页面工作正常,但我希望所有数据都在 sitemap.xml。 如何做到这一点?

<?php 
header("Content-type: text/xml");
echo '<?xml version="1.0" encoding="UTF-8" ?>';
include 'includes/connectdb.php';
?>

<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">

    <url>
        <loc>http://www.mobilesapp.com/</loc>
        <priority>1.00</priority>
    </url>

<?php
   $stmt = $con->prepare("SELECT url,modified FROM localnews");
   $stmt->execute();
   $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
   foreach($rows as $row){
?>
<url>
    <loc>http://www.mobilesapp.com/<?= $row['url'] ;?></loc>
    <lastmod><?= $row['modified']; ?></lastmod>
    <changefreq>always</changefreq>
    <priority>1</priority>
</url>
<?php } ?>

<?php
   $stmt = $con->prepare("SELECT url,modified FROM socialnews");
   $stmt->execute();
   $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
   foreach($rows as $row){
?>
<url>
    <loc>http://www.mobilesapp.com/<?= $row['url'] ;?></loc>
    <lastmod><?= $row['modified']; ?></lastmod>
    <changefreq>always</changefreq>
    <priority>1</priority>
</url>
<?php } ?>

</urlset>
    <?php 
    $xml = '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">';
    // mysql select
    foreach ($rows as $row) {
        // add next part to xml
        $xml .= '
        <url>
            <loc>http://www.mobilesapp.com/'.$row['url'].'</loc>
            <lastmod>'.$row['modified'].'</lastmod>
            <changefreq>always</changefreq>
            <priority>1</priority>
        </url>
        ';
    }
    $xml .= '</urlset>';
    // show 
    echo $xml;
    // and save to file 
    file_put_contents('sitemap.xml', $xml);
    ?>