【问题标题】:Echo something with PHP code in the xml file在 xml 文件中使用 PHP 代码回显某些内容
【发布时间】:2021-09-25 18:18:07
【问题描述】:

我是新手,我在 PHP 中工作。而且我对xml一无所知。我的英文不是很好。如果您看到错字,请编辑它

请看下面的代码

<?php 
header("Content-type: text/xml");
$array = ["a", "b", "c"];
echo $array[0];

输出有问题,无法使用回显。下面的照片是我的输出

请指导我

【问题讨论】:

    标签: php xml output echo


    【解决方案1】:

    我从您要创建站点地图的 url 中发现。您应该在xml 代码中看到输出。例如:

    <?php 
    header("Content-type: text/xml");
    $array = ["a", "b", "c"];
    
    echo "<?xml version='1.0' encoding='UTF-8'?>"."\n";
    echo "<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>"."\n";
     echo "<url>";
     echo "<loc>".$array[0]."</loc>";
     echo "<lastmod>".$array[1]."</lastmod>";
     echo "<changefreq>daily</changefreq>";
     echo "</url>";
    echo "</urlset>";
    

    【讨论】:

      【解决方案2】:

      如果您正在调试,请注释掉 header 行。设置内容类型标头后,仅以该内容类型输出。浏览器期待格式良好的 xml。所以仅仅打印出来是行不通的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-07-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多