PHP & XML help pls
Posted: March 3rd, 2009, 14:12
It's me again, with another annoying php issue.
I'm trying to do something that should be simple, and its only half working.
I have an xml file that provides something like this:
I'm trying to use simpleXML to parse this, using code like so:
Which works fine for the items stuff like <title> and <link>, eg: $entry->title and $entry->link
but as soon as i try to reference
eg: $entry->selection:title or $entry->selection:description
then it all goes tits up.
Anyone got any suggestions as to how i can do that?
I'm trying to do something that should be simple, and its only half working.
I have an xml file that provides something like this:
Code: Select all
<xml>
<xml>
<rss>
<channel>
<title>Gold Cup Odds - Affiliate Feeds</title>
<link>http://www.paddypower.com</link>
<description>Gold Cup Odds</description>
<language>en</language>
<pubDate>Tue, 03 Mar 2009 12:15:06 GMT</pubDate>
<dc>2009-03-03T12:15:06Z</dc>
<dc>en</dc>
<cf>list</cf>
<item>
<title>Cheltenham Gold Cup Chase 3m 2 1/2f - Denman</title>
<link>http://www.paddypower.com/bet?action=go_racing&ev_class_id=137&ev_type_id=5599&ev_id=1072000&gid=rss&bs_add_leg_to_slip=1&leg=stamp~|price_type~L|lp_num~6|lp_den~1|hcap_value~|selections~22428326</link>
<description>Horse Racing - CHELTENHAM - Event Time: 2009-03-13 15:20</description>
<pubDate>Fri, 13 Mar 2009 15:20:00 GMT</pubDate>
<guid>http://www.paddypower.com/bet?action=go_racing&ev_class_id=137&ev_type_id=5599&ev_id=1072000&gid=rss&bs_add_leg_to_slip=1&leg=stamp~|price_type~L|lp_num~6|lp_den~1|hcap_value~|selections~22428326</guid>
<dc>2009-03-13T15:20:00Z</dc>
<eventtype>5599</eventtype>
<eventclass>137</eventclass>
<event>Win or Each Way</event>
<event>3318315</event>
<selection>Denman</selection>
<selection>6 - 1</selection>
<event>1072000</event>
<event>2009-03-13 15:20:00.0</event>
<selection>22428326</selection>
<event>Cheltenham Gold Cup Chase 3m 2 1/2f</event>
<event>Cheltenham Gold Cup Chase 3m 2 1/2f</event>
<selection>Denman</selection>
<event>Horse Racing</event>
<event>CHELTENHAM</event>
<event>Horse Racing</event>
</item>
Code: Select all
function getFeed($feed_url) {
$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);
echo "<ul>";
foreach($x->channel->item as $entry) {
echo "<li><a href='$entry->link'>" . $entry->title . "</a></li>\n";
}
echo "</ul>";
}
but as soon as i try to reference
Code: Select all
<selection> or <selection>
then it all goes tits up.
Anyone got any suggestions as to how i can do that?