执行PHP语法时输出XML feed断点

时间:2017-10-20 10:31:22

标签: php xml

我正在尝试MVC基于此结构的简单XML图像源。

这将始终是1 - 20。

<image1>http://test.url/test.jpg</image1>
<caption1>This is a test caption <caption1 />
<credit1>This is a test credit</credit1>

这是我的剧本:

echo "<images>"; 
for($i = 1; $i <= 20; $i++) { 
   $imageUrl = "image$i";
   $caption = "caption$i";
   $credit = "credit$i";
   echo "<image no='$i'>";
   echo "<imageurl>" . $gallery->$imageUrl . "</imageurl>";
   echo "<caption>" . $gallery->$caption . "</caption>";
   echo "<credit>" . $gallery->$credit . "</credit>";
   echo "</image>";
}
echo "</images>";

它作为变量$xml返回,我输出如下:

$xmlProcessor = new GalleryXMLProcessor();
$xml = $xmlProcessor->processFeed("http://testurlexport.php");
header('Content-Type: text/xml;  charset=UTF-8');       
echo $xml;

但是,我只是将输出作为文本而不是XML返回。它似乎只是echo。我在Chrome上有一个XML查看器,它不会将XML呈现在其预期的UI中。在我开始添加图像之前,这很好(见下文)

enter image description here

1 个答案:

答案 0 :(得分:0)

听起来回声正在返回text / xml。尝试将返回的xml的mime类型更改为application / xml

相关问题