Jump to content

get index of foreach xml


chiqui3d

Recommended Posts

hi very good

I'm trying to get the indices of the gallery that I have a xml file to display it in a <select>

xml file is as follows ..

I'm trying to use "foreach" but what brings me, is twice galleria, but that's fine, what happens is that it brings are the names, but I want indices, 0 and 1

xml file

<?xml version="1.0"?>
<content>
<gallery Name="Hostal" Folder="Gallery/hostal">
<image Thumb="thumb0.jpg" Large="0.jpg" Caption="Hostal Regina" Colour="181f0a">
<comentarios><![CDATA[<p>Hostal Regina comentarios</p>]]></comentarios>
    </image>
    <image Thumb="thumb1.jpg" Large="1.jpg" Caption="Hostal Regina" Colour="181f0a">
<comentarios><![CDATA[<p>Hostal Regina</p>]]></comentarios>
    </image>
  </gallery>
<gallery Name="Vistas" Folder="Gallery/nerja">
    <image Thumb="thumb0.jpg" Large="0.jpg" Caption="Vista Nocturna" Colour="eeeeeee">
<comentarios><![CDATA[<p>Vista Nocturna realizada por Diego Palomo</p>]]></comentarios>
    </image>
<image Caption="eeeeeee"><comentarios>http://php-design-patterns.com</comentarios></image>
</gallery>
</content>

file select form

<select name="action">
<option value="">Escoger de la Lista</option>
<?php
$source = 'content.xml';
// load as string
$xmlstr = file_get_contents($source);
$sitemap = new SimpleXMLElement($xmlstr);
// load as file
$sitemap = new SimpleXMLElement($source,null,true);
foreach($sitemap->gallery as $index=>$content) {
$atributo = $content->attributes();
echo "<option value='".$index."'>".$index. "</option>";///in value no show index


}
?>
</select>

Link to comment
https://forums.phpfreaks.com/topic/213389-get-index-of-foreach-xml/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.