2011-09-09 67 views
-2

我试图解析这个XML饲料使用simplexml_load_file解析[@属性] =>阵列

[0] => SimpleXMLElement Object 
      (
       [title] => Johannesburg in November 
       [link] => SimpleXMLElement Object 
        (
         [@attributes] => Array 
          (
           [rel] => alternate 
           [type] => text/html 
           [href] => http://www.tompeters.com/dispatches/012120.php?rss=1 
          ) 

        ) 

       [id] => tag:www.tompeters.com,2011://2.12120 
       [published] => 2011-09-08T14:03:23Z 
       [updated] => 2011-09-08T14:11:49Z 
       [summary] => Tom will be giving a day-long presentation in November in Johannesburg, South Africa. Our friends at the Business Results Group... 
       [author] => SimpleXMLElement Object 
        (
         [name] => Shelley Dolley 
        ) 

       [category] => SimpleXMLElement Object 
        (
         [@attributes] => Array 
          (
           [term] => Announcements 
           [scheme] => http://www.sixapart.com/ns/types#category 
          ) 

        ) 

       [content] => SimpleXMLElement Object 
        (
         [@attributes] => Array 
          (
           [type] => html 
          ) 

        ) 

      ) 

我的PHP代码,这样做是

$url = 'http://www.tompeters.com/atom.xml'; 
       $xml = simplexml_load_file($url); 

       echo '<pre>'; 
       foreach($xml->entry as $entry){ 
        echo $entry->title; 
        echo "<br />"; 
        foreach ($entry->link->@attributes as $attr){ 
         echo $attr->href; 
         echo "<br />"; 
        } 
       } 

的问题是,@attributes位打破代码..

我如何获得该HREF链接?

+0

你*打破了代码*说明是*的变化不工作plz帮助*。我相信你可以改进它。 –

+1

@ÁlvaroG. Vicario对不起,我不明白你刚刚说了什么? –

+0

我的意思是说,你应该提供一个清晰的问题描述并提出一个问题,而不是放下一段代码,让我们猜测。比较«打破了代码»与«触发以下语法错误:‘意外‘@’,期待T_STRING或T_VARIABLE或‘{’或‘$’’»的 –

回答