2011-03-26 57 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>一个孩子。