我如何从xml中获取这个?

时间:2011-07-08 16:58:28

标签: php xml

如何从此xml中获取链接href(在已发布的节点下):

<entry>
<id>tag:search.twitter.com,2005:8927670fcdf59031552</id>
<published>2011-07-08T10:16:40Z</published>
<link type="text/html" href="http://twitter.com/username/statuses/892767c088fds031552" rel="alternate"/>
<title>dfdf</title>
<content type="html">fdf</content>
<updated>2011-07-08T10:16:40Z</updated>
<link type="image/png" href="http://a0.twimg.com/profile_images/14014071/RV_normal.JPG" rel="image"/>
<twitter:geo>
</twitter:geo>
<twitter:metadata>
  <twitter:result_type>recent</twitter:result_type>
</twitter:metadata>
<twitter:source>&lt;a href=&quot;http://www.tweetdeck.com&quot; rel=&quot;nofollow&quot;&gt;TweetDeck&lt;/a&gt;</twitter:source>
<twitter:lang>en</twitter:lang>
<author>
  <name></name>
  <uri></uri>
</author>

当我有这个php:

 $xml = simplexml_load_file("http://search.twitter.com/search.atom?q=from%3Ausername&rpp=10");
        if($xml) {
                    $url = $xml->entry->link->href;
                      $status = $xml->entry->title;

问题我看到有多个链接节点,并且链接节点还有多个属性..

2 个答案:

答案 0 :(得分:2)

试试这个:

$xml->entry->link[0]->attributes()->href; //this is for the first href node

答案 1 :(得分:0)

尝试:

$url = $xml->entry->link[0]->href;