在 xml 文件中使用 PHP 代码回显某些内容

Echo something with PHP code in the xml file

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

请看下面的代码

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

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

请指导我

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

我从 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>";