问题
I'm trying to retrieve feeds from a twitter search to display on various parts of the site. I modified this function to do this yet it works for every feed a try it on except twitter.
function getFeed($feed_url) {
$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);
echo "<ul>";
foreach($x->channel->item as $entry) {
echo "
<li>
<a href='$entry->link' title='$entry->title'>" . $entry->title . "</a>
</li>";
}
echo "</ul>";
}
I am after only the content of the various associative posts. Here is a sample call.
<?php getFeed("feed://search.twitter.com/search.atom?q=berkshire+golf"); ?>
Any ideas,
Marvellous
回答1:
Twitter's search API is just a simple HTTP request, so your URL should be http://
and not feed://
if you're using file_get_contents
Edit:
You're also using .atom
, use rss instead:
http://search.twitter.com/search.rss?q=berkshire+golf
来源:https://stackoverflow.com/questions/6001765/php-xml-feed-assembler-works-for-every-feed-except-twitter