Jump to content

simple xml - how do I display an image


adrian28uk

Recommended Posts

I have just discovered found an example of using simple xml with php5.

 

I have been trying to apply this to an .xml document I was given. So far I have managed to output basic info, however I am now scratching my head on how I would output one of the images.

 

I have pasted the source for the .php page and also a sample from the .xml doc below this.

 

Look forward to your help.

 

----------- output.php --------------------------

<?php

//Since we're already using PHP5, why don't we exploit their easy to use file_get_contents() command?

$xmlFileData = file_get_contents("input.xml");

//Here's our Simple XML parser!

$xmlData = new SimpleXMLElement($xmlFileData);

 

//Outputing all of our XML to people

foreach($xmlData->property as $property) {

print($property->id . "<br />");

print($property->town. "<br />");

print($property->province ."<br />");

print($property->images["image id"] ."<br />");

}

?>

 

 

------------ input.xml ------------------------------

<root>

 

<property>

<id>1126</id>

<date>2008-06-26 01:12:06</date>

<ref>LO1000</ref>

 

<price>238000</price>

<price_freq>sale</price_freq>

<part_ownership>0</part_ownership>

<leasehold>0</leasehold>

<type>

<en>Villa</en>

</type>

 

<town>Lorca</town>

<province>Alicante</province>

<location_detail>Costa Calida</location_detail>

<beds>3</beds>

<baths>0</baths>

<pool>0</pool>

 

<url>http://www.casitas-pego.com/costa-blanca-property/property_detail_new.php?Id=1126</url>

<desc>

<en>A Spacious Villa on a huge 5,800m2 Plot of land, this is a brand new house, finished in 2007. With wonderful views from every angle this is an ideal location , minutes from Lorca and just a kilometre from the Medical Centre make this not only private, yet accessible.With pre-installation for Central Heating and Air Conditioning and all modern conveniences, this is a property that won i`t be on the market for long!</en>

</desc>

<images>

<image id="1">

<url>http://www.casitas-pego.com/admin/images/350X233/LO1000/1.JPG</url>

 

<primary>1</primary>

<title>

<en>Image 1</en>

</title>

</image>

 

<image id="2">

<url>http://www.casitas-pego.com/admin/images/350X233/LO1000/2.JPG</url>

 

<primary>0</primary>

<title>

<en>Image 2</en>

</title>

</image>

 

</images>

</property>

 

</root>

Link to comment
https://forums.phpfreaks.com/topic/127340-simple-xml-how-do-i-display-an-image/
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.