parse and display each node by way of foreach loop
i am trying to parse usernames on a twitter rss feed using simplexml in php. there are a total of 16 names so i will like to use the foreach loop to run parse each one and return them. my only problem is the foreach loop.
$url = file_get开发者_如何学JAVA_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;
}
Not sure what error you're having. But, judging from the feed itself, it seems that $match->name(0)->nodeValue
is incorrect; as nodeValue
is not a method of the SimpleXML
library, but rather the Document Object Model
library.
You can replace all occurrences of $match->name(0)->nodeValue
with $match->author->name
as ->name
will output the node value for the tag <name>
, which is a child of <author>
.
精彩评论