Let's see the following example:
$str = <<< END
nowhere@notadomain.tld
unknown@unknown.tld
there is no subject
symbols]]>
END;
$sxml = simplexml_load_string($str);
foreach ($sxml->email as $email)
echo $email['type'];
?>
This will display the text mime in the output window. So if you look carefully, you
will understand that each node is accessible like properties of an object, and all
attributes are accessed like keys of an array. SimpleXML makes XML parsing
really fun.
Parsing Flickr Feeds using SimpleXML
How about adding some milk and sugar to your coffee? So far we have learned what
SimpleXML API is and how to make use of it. It would be much better if we could
see a practical example. In this example we will parse the Flickr feeds and display
the pictures. Sounds cool? Let's do it.
If you are interested what the Flickr public photo feed looks like, here is the content.
The feed data is collected from http://www.flickr.com/services/feeds/photos_
public.gne:
Chapter 8
[ 199 ]
Pages:
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215