简体   繁体   中英

Doesn't do anything - 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?

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.
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM