Results 1 to 1 of 1
-
10th Feb 2012, 06:54 PM #1OPThe Wise OneWebsite's:
twilight.ws ddlrank.com[PHP] Twitter Feed Reader + Caching
Hey,
Coded something yesterday. Basically it fetches the tweets of someone and saves them in a temporary file which is updated every hour. (You can modify this). It's a quick code mock-up and I wouldn't put it on a production website before testing it.
PHP Code:<?php
$username = 'TwitterUserNameHere';
$limit = 5;
$feed = 'http://twitter.com/statuses/user_timeline.rss?screen_name='.$username.'&count='.$limit;
$tweets = file_get_contents($feed);
$tweet = explode("<item>", $tweets);
$tcount = count($tweet) - 1;
for ($i = 1; $i <= $tcount; $i++) {
$find = array('–', $username);
$replace = array('-', '');
$endtweet = explode("</item>", $tweet[$i]);
$title = explode("<title>", $endtweet[0]);
$content = explode("</title>", $title[1]);
$tweetItem = str_replace($find, $replace, $content[0]);
$tweetItem = preg_replace('#(http:\/\/([a-zA-Z0-9\.\/]+))#','<a rel="nofollow" href="$1">$1</a>',$tweetItem);
$mytweets[] = $tweetItem;
}
$tweetout = '<ul>';
while (list(, $v) = each($mytweets)) {
$tweetout .= "<li>$v</li>";
}
$tweetout .= '</ul>';
$twitterTempFile = 'twitterfeed.temp';
$lastModified = filemtime($twitterTempFile);
if ($lastModified < strtotime("-1 hour")){
$fh = fopen($twitterTempFile, 'w+') or die('Unable to open file');
fwrite($fh, $tweetout);
fclose($fh);
}else{
$tweetout = file_get_contents($twitterTempFile);
}
echo $tweetout;
Remember, this is just something I put together in a few minutes, it's not written very good (I code better usually lol even if I say so myself).
Oh well, enjoy I guess
+ rep is appreciated if you can use this codeWhoo Reviewed by Whoo on . [PHP] Twitter Feed Reader + Caching Hey, Coded something yesterday. Basically it fetches the tweets of someone and saves them in a temporary file which is updated every hour. (You can modify this). It's a quick code mock-up and I wouldn't put it on a production website before testing it. <?php $username = 'TwitterUserNameHere'; $limit = 5; $feed = 'http://twitter.com/statuses/user_timeline.rss?screen_name='.$username.'&count='.$limit; Rating: 5
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
How to publish fresh To Twitter Feed
By smookyguns in forum Webmaster DiscussionReplies: 0Last Post: 15th Oct 2012, 07:51 PM -
Optimizing APC Caching
By m1mi.dan0s in forum Webmaster DiscussionReplies: 3Last Post: 3rd Oct 2012, 08:37 AM -
RSS Reader
By TheLorenalex in forum Technical Help Desk SupportReplies: 1Last Post: 30th Oct 2011, 03:07 AM -
[Buying] RL with Newsgroup reader
By only1_PO in forum Completed TransactionsReplies: 0Last Post: 22nd Oct 2011, 07:00 PM -
[c#] XML Reader / Writer
By jayfella in forum Web Development AreaReplies: 13Last Post: 16th Jun 2010, 11:22 PM
themaPoster - post to forums and...
Version 5.36 released. Open older version (or...