duanhe7471
duanhe7471
2012-11-21 11:20

xml如何在php中解析

已采纳

I have this xml

http://www.scorespro.com/rss/live-soccer.xml

the structure is this :

 <rss>
 <channel>
 <item>
 <title>
 </title>
 </item>
 </channel>
 </rss>

I want to get the information about the titles, so i'm trying to do this, but without success.

  $xml = simplexml_load_file('http://www.scorespro.com/rss/live-soccer.xml');
foreach($xml->item as $item)
 {
 echo $item->title;
 } 

I already did print_r($xml) to see if is parsing correctly the url that i'm giving.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dtrotfd1012 dtrotfd1012 9年前

    $xml has root node, in this case <rss>:

    foreach($xml->channel->item as $item)
    

    You can also use XPath to get the items:

    $items = $result = $xml->xpath('/rss/channel/item');
    
    点赞 评论 复制链接分享