在php上的浏览器上打印xml文本

时间:2013-12-08 16:27:10

标签: php

拥有一个充满图像的目录,现在我想在php浏览器中打印类似xml行的东西

<image>
    <thumb_path>amor/thumbs/1_cuadro_de_amor.jpg</thumb_path>
    <image_path>amor/1_cuadro_de_amor.jpg</image_path>
    <transition_type>swipe_from_left_to_right</transition_type>
    <transition_duration>1</transition_duration>
    <transition_delay>3</transition_delay>
    <description_window from="left" to_x="55" to_y="0" duration="1" delay="0"><![CDATA[<p class="descRed1_1">1.- Cuadro de amor</p>]]></description_window>
  </image>

所以我创建了一个php文件并将其上传

$dir = 'amor';
$count=1;
foreach (glob($dir.'/*.*') as $filename)
{
    if($filename=="." || $filename==".." || $filename=="download.php" || $filename=="index.php")
    {
        //this will not display specified files
    }
    else
    {
        echo 'header ("Content-Type:text/xml");';
        echo '<image>';
        echo '  <thumb_path>'.$dir.'/thumbs/'.$filename.'</thumb_path>';
        echo '  <image_path>'.$dir.'/"'.$filename.'</image_path>';
        echo '  <transition_type>swipe_from_left_to_right</transition_type>';
        echo '  <transition_duration>1</transition_duration>';
        echo '  <transition_delay>3</transition_delay>';
        echo '  <description_window from="left" to_x="55" to_y="0" duration="1" delay="0"><![CDATA[<p class="descRed1_1">'.$count.'.- "'.ucfirst(str_replace("_"," ",$filename)).'</p>]]></description_window>';
        echo "</image>";
        echo "<br>";
        $count++;
    }
}

但xml标签显示不正确,我缺少什么 我尝试添加

echo 'header ("Content-Type:text/xml");';

但没有效果

我到了 amor / thumbs / amor / 1_cuadro_de_amor.jpg amor /“amor / 1_cuadro_de_amor.jpg swipe_from_left_to_right 1 3 1.-”Amor / 10 cuadro de alegra.jpg

]]&GT;

我如何摆脱文件名上的dir字符串,在本例中是“amor”?

1 个答案:

答案 0 :(得分:1)

删除该语句的'echo'部分。你只想要

标题(“Content-Type:text / xml”);

你可能也想把它放在最上面:

确保第一个xml标记之前没有空格,否则会出错。