Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP5 and XML HELP! :(

Featured Replies

Hi there,

 

I have an XML file with the following structure,

 

<item>
<name></name>
<description></description>
<Images>
<img src="" alt="" width="" height="" />
<img src="" alt="" width="" height="" />
<img src="" alt="" width="" height="" />
<img src="" alt="" width="" height="" />
</Images>
</item>

their are about 100 items but when i loop through each item and echo them onto the screen I only one to display one of the images that is listed..

 

Can anyone help me with the code to display just one?

 

I have tried:

 

$item->Images

$item->Images->img[1]->attributes()->src

 

but this does not seem to display anything and I know that using children() will just show a count of the children..

 

Im pulling my hair out and it seems like such a small problem

 

Thanks,

Chris

  • Author

its on the same server This is the code that I am using so far..

 

$inventorylink = 'inventory.xml';

$feed = simplexml_load_file($inventorylink);	


// Display Results

foreach ($feed->item as $item) {

echo "<tr>";
echo"<td><strong><a href=\"\" title=\"\">$item->title</a></strong></td>";
echo "<td rowspan=\"2\" style=\"vertical-align:top; padding-bottom:15px;\">$item->Images->img[1]->attributes()->src</td>";
echo "</tr>";
echo "<tr>";
echo "<td><strong>Features:</strong> $item->description <br /><a href=\"\" title=\"More Details On The $item->title\">More Details</></td>";
echo "</tr>";

} 

 

I hope this makes sense

 

Thanks,

Chris

You've done it the right way, however you need to either remove the string out of the double quotes or surround it with { } changing

$item->Images->img[1]->attributes()->src

to

{$item->Images->img[1]->attributes()->src}

Also img[1] is the second images value, as the array is 0 based

 

  • Author

Thats great! so annoyed I didnt try that :(

 

Thanks for your help!!

  • Author

Hey Jay,

 

How would I go about echoing all the images out on the page for each item rather than just one?

 

some items have multiple images and some have none :S

 

Thanks,

Chris

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.