2012-03-06 56 views
0

我有这个链接http://lazhalazha.livejournal.com/data/rss其中有RSS,我需要的是​​值的数组,即链接到帖子。这是我迄今为止...PHP对象 - 我怎样才能访问这个值

$xml = simplexml_load_file('http://lazhalazha.livejournal.com/data/rss'); 
foreach ($xml->channel->item as $item){ 
    print_r($item->guid); 
} 

输出是一系列的这些对象

SimpleXMLElement Object 
(
    [@attributes] => Array 
     (
      [isPermaLink] => true 
     ) 

    [0] => http://lazhalazha.livejournal.com/713.html 
) 

此对象转换为字符串解决这一点,那么它传递正确的网址,而不是对象。

$xml = simplexml_load_file('http://lazhalazha.livejournal.com/data/rss'); 
$linkArray = array(); 
foreach ($xml->channel->item as $item){ 
    $guid = (string)$item->guid; 
    array_push($linkArray, $guid); 
} 
+0

什么'不work'关于你的第一个选项? – Neal 2012-03-06 14:44:12

+0

@Neal输出与末尾没有[0]相同。 – sed 2012-03-06 14:46:00

+1

请通过php手册中的simplexml基本用法示例。 – Gordon 2012-03-06 14:50:02

回答

0
<?php 
$_temp = array(); 
$xml = simplexml_load_file('http://lazhalazha.livejournal.com/data/rss'); 

foreach ($xml->channel->item as $item){ 
    $_temp[] = (string)$item->guid[0]; 
} 

print_r($_temp); 
?>