Accessing identically named elements : simplexml_load_string « XML « PHP

Accessing identically named elements

<?xml version="1.0" encoding="utf-8" ?>
<rss version="0.91">
  <title>What's For Dinner</title>

$xml = simplexml_load_string($menu);

print "Title: " . $xml->channel->item[0]->title . "\n";
print "Title: " . $xml->channel->item[1]->title . "\n";
print "Title: " . $xml->channel->item[2]->title . "\n";

Related examples in the same category

1.Adding attributes
2.Changing elements and attributes
3.Loop through children
4.Loading an XML document from a file
5.Fetching a remote XML document
6.Parsing XML in a string
7.Parsing an XML Document with SimpleXML
9.Loading a remote XML document
10.Outputting XML
11.Using SimpleXML to extract data
12.Simple XML
13.Print XML element attributes
14.Printing sub-element contents
15.Saving an XML document to a file