2011-03-26 58 views
0

我想在php中使用simplexml解析twitter上rss feed的用戶名。總共有16個名字,所以我想使用foreach循環來運行解析每一個並返回它們。我唯一的問題是foreach循環。解析並通過foreach循環顯示每個節點

$url = file_get_contents("http://search.twitter.com/search.atom?q=basketball"); 
$source = simplexml_load_string($url); 

foreach ($source as $match){ 
    $output = $match->name(0)->nodeValue = substr($match->name(0)->nodeValue, 0, strpos($match->name(0)->nodeValue, ' ')); 
    echo $output; 
} 
+0

請輸入'$ source' – diEcho 2011-03-26 08:05:36

回答

0

不知道你有什麼錯誤。但是,從飼料本身來看,似乎$match->name(0)->nodeValue是不正確的;因爲nodeValue不是SimpleXML庫的方法,而是Document Object Model庫。

您可以$match->author->name->name將輸出替換$match->name(0)->nodeValue出現的所有節點值的標籤<name>,這是<author>一個孩子。