doushijia5684 2015-06-23 19:06
浏览 25
已采纳

什么都不做 - simpleXML PHP

It's not doing anything when I run it... I suppose It should write something like:

O nás Produkty

Here is the PHP code (line 50 because it's inside HTML code):

<?php
$menu=simplexml_load_file('menu.xml') or die('Cannot read menu!');
foreach((array) $menu->menu_items->item as $HTMLTAG)
{
echo $HTMLTAG;
} 
?>

And here is a part of the XML:

<?xml version="1.0" encoding="utf-8"?>
<menu_items>
<item link_url="#" active="on">O nás
<subitem link_url="/about" active="on">O nás</subitem>
<subitem link_url="/about/reference" active="on">Reference</subitem>
<subitem link_url="/about/contact" active="on">Kontakty</subitem>
</item>
<item link_url="#" active="on">Produkty
<subitem link_url="/HeatMatrix" active="on">O nás
<under_subitem link_url="/HeatMatrix/LUVO">Předehřívač vzduchu LUVO</under_subitem>
<under_subitem link_url="/HeatMatrix/HV">Hybridní výměníky</under_subitem>
<under_subitem link_url="/HeatMatrix/KP">Výměníky kapalina-plyn</under_subitem>
<under_subitem link_url="/HeatMatrix/VCS">Vestavěný čistící systém</under_subitem></subitem>
<subitem link_url="/OCR" active="off">OCR systémy</subitem>
<subitem link_url="/LDR" active="off">Točivé redukce</subitem>
</item>
</menu_items>

Don't you know what should I do about it?

  • 写回答

1条回答 默认 最新

  • dsf11t5u1651 2015-06-23 19:29
    关注

    The ->menu_items also does not need to be there, since it is the root node of the XML document. This worked for me:

    foreach($menu->item as $HTMLTAG)
    {
        echo $HTMLTAG; //I used print_r here actually, which was nicer.
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)