With PHP 5, you can use either simplexml_load_file() or simplexml_load_string() to get an instance of the SimpleXMLElement class.
This is a massively simplified feed from Digg. (Shame the example didn't include anything about Kanye West being a big jackass to Taylor Swift)
01.
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
02.
<
rss
version
=
"2.0"
>
03.
<
channel
>
04.
<
title
>digg.com: Stories / Popular</
title
>
05.
<
language
>en-us</
language
>
06.
<
description
>digg.com: Stories / Popular</
description
>
07.
<
link
>http://digg.com/<;/
link
>
08.
<
item
>
09.
<
title
>6 Russian Volcanoes Erupt Simultaneously</
title
>
10.
<
link
>http://feeds.digg.com/~r/digg/popular/~3/ufca-hKu7hM/6_Russian_Volcanoes_Erupt_Simultaneously</
link
>
11.
<
description
>*****</
description
>
12.
<
pubDate
>Wed, 16 Sep 2009 22:30:01 +0000</
pubDate
>
13.
<
guid
isPermaLink
=
"false"
>http://digg.com/environment/6_Russian_Volcanoes_Erupt_Simultaneously<;/
guid
>
14.
</
item
>
15.
<
item
>
16.
<
title
>Happiness: The New Currency in France</
title
>
17.
<
link
>http://feeds.digg.com/~r/digg/popular/~3/7hQDWvQwx5A/Happiness_The_New_Currency_in_France</
link
>
18.
<
description
>Gross domestic product, inflation, unemployment- these are old-fashioned, Anglo-Saxon indicators of national wellbeing, says the president of France. From now on, the country's economic progress will be measured in terms of happiness.</
description
>
19.
<
pubDate
>Wed, 16 Sep 2009 22:10:02 +0000</
pubDate
>
20.
<
guid
isPermaLink
=
"false"
>http://digg.com/health/Happiness_The_New_Currency_in_France<;/
guid
>
21.
</
item
>
22.
<
item
>
23.
<
title
>The 15 Weirdest Music Videos Of All Time</
title
>
24.
<
link
>http://feeds.digg.com/~r/digg/popular/~3/QTH3TyAZma0/The_15_Weirdest_Music_Videos_Of_All_Time</
link
>
25.
<
description
>Music videos changed the music industry completely. Artists were finally given a "visual voice" and fans were able to put faces with names. Musicians are often a little quirky however, resulting in many truly bizarre videos.</
description
>
26.
<
pubDate
>Wed, 16 Sep 2009 22:00:01 +0000</
pubDate
>
27.
<
guid
isPermaLink
=
"false"
>http://digg.com/music/The_15_Weirdest_Music_Videos_Of_All_Time<;/
guid
>
28.
</
item
>
29.
</
channel
>
30.
</
rss
>
To parse the items in this list, simply use the following.
01.
$rss
= simplexml_load_file(
"http://feeds.digg.com/digg/popular.rss"
);
02.
03.
echo
"Parsing feed with title: "
.
$rss
->channel->title;
04.
05.
foreach
(
$rss
->channel->item
as
$item
) {
06.
echo
$item
->title;
07.
echo
$item
->link;
08.
echo
$item
->description;
09.
echo
$item
->guid;
10.
}
And there you have it, very simple.