Posts: 876
Name: Matt Pealing
Location: England, north west
|
Actually this one seems to work quite well:
PHP Code:
<?php $username = "username"; $limit = 5; $feed = 'http://twitter.com/statuses/user_timeline.rss?screen_name='.$username.'&count='.$limit; $tweets = file_get_contents($feed); $tweets = str_replace("&", "&", $tweets); $tweets = str_replace("<", "<", $tweets); $tweets = str_replace(">", ">", $tweets); $tweet = explode("<item>", $tweets); $tcount = count($tweet) - 1;
for ($i = 1; $i <= $tcount; $i++) { $endtweet = explode("</item>", $tweet[$i]); $title = explode("<title>", $endtweet[0]); $content = explode("</title>", $title[1]); $content[0] = str_replace("–", "—", $content[0]); $content[0] = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/", '<a href="http://$2$3" target="_blank">$1$2$4</a>', $content[0]); $content[0] = str_replace("$username: ", "", $content[0]); $content[0] = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $content[0]); $content[0] = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $content[0]); $mytweets[] = $content[0]; }
while (list(, $v) = each($mytweets)) { $tweetout .= "<li>$v</li>"; } ?>
Only thing is, it doesn't output the date of the Tweets. I can see it is contained within the XML inside the '<pubdate>' elements, which are inside the '<item>' elements. But I cannot figure out how to retrieve it without messing up the for loop!
One thing that does confuse me is that the script looks for '<title>' elements, but when I set the script to pull in my tweets, there appears to be no XML element called '<title>' in there anywhere
Does anybody have any ideas?
Last edited by pealo86; 12-11-2010 at 08:44 AM..
|