0

I have an XML file. It looks like the following :

<Offers>
 <Offer>
  <OfferID>1</OfferID>
  <OfferName>Offer One</OfferName>
 </Offer>
 <Offer>
  <OfferID>2</OfferID>
  <OfferName>Offer Two</OfferName>
 </Offer>
</Offers>

I have a variable declared like below :

$latest_offers = simplexml_load_file("Offers.xml");

Now my problem is how i can get a out put like this :

foreach($offer as $item)
{
 echo <offerID>, <OfferName>...each and everything inside the offer nod
}

How can i achieve this. Tried a lot but no success.

3
  • Knowing what the simplexml_load_file()-method does would be nice... Commented Nov 9, 2012 at 7:13
  • 1
    @looper - Really!, simplexml_load_file is PHP function and not user defined. Commented Nov 9, 2012 at 7:18
  • @PushPesh - Oops, sorry for that. Awkward. Commented Nov 9, 2012 at 7:20

1 Answer 1

1

Try this.

<?php
$latest_offers = simplexml_load_file("Offers.xml");
foreach($latest_offers->Offer as $offer) {
   echo $offer->offerID . ', ' . $offer->OfferName . '<br>';
}
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.