Get a Twitter feed to my website using PHP
I was just wondering, what PHP methods would I use to get the most recent tweet of a twitter user to display in a box on my website?
any suggestions on how i may achieve this would be g开发者_如何学Creat.
cheers
There is also a built in simplexml function:
// Parse the raw xml
$xml = simplexml_load_file('http://twitter.com/statuses/user_timeline/{yourfeed}.rss');
// Go through each tweet
foreach ($xml->channel->item as $tweet)
{
echo $tweet->title . '<br />';
}
Try a library: http://dev.twitter.com/pages/libraries#php
Or, if those seem like overkill for some reason, load the feed via cURL and simplexml_load_string. Manipulate as needed.
This will show your last tweet:
<?php
$ch = curl_init("http://twitter.com/statuses/user_timeline/{yourtwitterfeed}.rss");
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$data = simplexml_load_string(curl_exec($ch));
curl_close($ch);
echo $data->channel->item[0]->title;
EDIT : Ha. Or you can use simplexml_load_file("{url goes here}") instead of all that cURL stuff. I forgot you can do that.
精彩评论