尝试使用PHP通过XML加载图像时,图像未显示在浏览器中

时间:2016-12-05 04:19:53

标签: php xml xml-parsing

我在data.xml文件中有这个

<?xml version="1.0" encoding="UTF-8"?>
<TVchannel> //This is the root element that consists of IT, PTG and HR tv

    <monthname month="September">  

        <channelname name="IT">  
            <title>Welcome to IT TV</title> 
        <images>
        <image path="image1.png"/>
        <image path="image2.png"/>
        </images>
        </channelname>

        <channelname name="PTG">
            <title>Welcome to PTG TV</title>
        <images>
        <image path="image3.jpeg"/>
        <image path="image4.jpeg"/>
        </images>
              </channelname>

        <channelname name="HR">
            <title>Welcome to HR TV</title> 
        <images>
        <image path="image5.jpeg"/>
        <image path="image6.jpeg"/>
        </images>   
        </channelname>

    </monthname>

    <monthname month="October"> //the view for a different month

        <channelname name="IT">
            <title>Welcome to IT TV</title>   
        </channelname>

        <channelname name="PTG">
            <title>Welcome to PTG TV</title>    
        </channelname>

        <channelname name="HR">
            <title>Welcome to HR TV</title>         
        </channelname>

    </monthname>

</TVchannel>

我有这个php文件,它使用simplexml加载这个data.xml并迭代以获取每个图像。

<?php
    $picture_container = simplexml_load_file('data.xml');
    $title_bar = $picture_container->{'monthname'}[0]->{'channelname'}[0]->title;
    echo $title_bar;

header("content-type: image/png");
    foreach($picture_container->{'monthname'}[0]->{'channelname'}[0]->images->image as $iterator)
     {  
        echo '<img src="'.$iterator['path'].'"/>';      

    }

?>

浏览器未显示任何错误,但显示空图标。 (见图) The browser does not show me any error but show an empty icon(see pic).The weird concentric rectangles!!!

请帮帮我..谢谢

1 个答案:

答案 0 :(得分:-2)

解决 在foreach循环中写这个

echo '<img src="'.$iterator['path'].'" height="100"; "width="100" ;>';