duanraa1984 2016-12-05 04:19
浏览 41
已采纳

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

I have this in the data.xml file

<?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>

I have this php file which uses simplexml to load this data.xml and iterate to get each image.

<?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 displays an empty icon. (see pic) The browser does not show me any error but show an empty icon(see pic).The weird concentric rectangles!!!

Please help me..Thanks

  • 写回答

2条回答 默认 最新

  • dongshan4518 2016-12-05 04:25
    关注

    Since you're targeting the attribute path, the use ->attributes() :)

    echo $iterator->attributes()->path;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态