How to Get Your Most Recent Twitter Posts Using PHP with Caching

When we started redesigning the Pop Art blog, one of the chief requirements was to integrate everyone’s Twitter feeds into the site. In addition to the Pop Art Twitter feed in the sidebar, we wanted to add individual twitter feeds on the profile pages. The problem is that the javascript code that Twitter provides can only be called once in a single page, or it gets confused.

Since we were switching to WordPress, I checked out a bunch of Twitter plugins, but ultimately found them all to be unreliable or just missing features. In the end, I hacked together one of my own, based heavily on code by Ryan Barr. His PHP script was very nearly perfect, but I ran into three problems.

First, his script echoed out the exact date and time of the tweet, but I wanted the fancy “2 hours ago” style dates. To do that, I used a chunk of code from Stack Overflow. Now, I’m far from an advanced PHP programmer, so I’m sure that this code could be cleaned up and condensed down to something like 12 characters, but I like this because it works, and it’s very easy for a mid-level programmer like myself to understand.

<?php
/*
	Relative Time Function
	based on code from http://stackoverflow.com/questions/11/how-do-i-calculate-relative-time/501415#501415
	For use in the "Parse Twitter Feeds" code below
*/
define("SECOND", 1);
define("MINUTE", 60 * SECOND);
define("HOUR", 60 * MINUTE);
define("DAY", 24 * HOUR);
define("MONTH", 30 * DAY);
function relativeTime($time)
{
	$delta = strtotime('+2 hours') - $time;
	if ($delta < 2 * MINUTE) {
		return "1 min ago";
	}
	if ($delta < 45 * MINUTE) {
		return floor($delta / MINUTE) . " min ago";
	}
	if ($delta < 90 * MINUTE) {
		return "1 hour ago";
	}
	if ($delta < 24 * HOUR) {
		return floor($delta / HOUR) . " hours ago";
	}
	if ($delta < 48 * HOUR) {
		return "yesterday";
	}
	if ($delta < 30 * DAY) {
		return floor($delta / DAY) . " days ago";
	}
	if ($delta < 12 * MONTH) {
		$months = floor($delta / DAY / 30);
		return $months <= 1 ? "1 month ago" : $months . " months ago";
	} else {
		$years = floor($delta / DAY / 365);
		return $years <= 1 ? "1 year ago" : $years . " years ago";
	}
}
?>

Secondly, and most important, Ryan’s code didn’t cache the results. That’s obviously bad form, but I didn’t really think about trying to fix it until Apple’s WWDC traffic drove Twitter to a standstill while I was testing our new site. Realizing that our Twitter feeds would die anytime anything big happened on the internet motivated me, and I was able to integrate some caching code from Kien Tran and Snipplr that meshed well with Ryan’s existing code.

When I was done, I had a fully functional script that created a cache file for each twitter feed, and only tried to update it every ten minutes. I was especially pleased to discover that it worked when Twitter again ground to a halt due to the Iran elections and Michael Jackson’s death in the last few weeks.

So here’s the final code that we’re using on the Pop Art blog. It looks pretty overwhelming, but it’s basically broken down into three sections. First, it checks to see if the cache file exists, and whether it needs to be updated. Second, it parses the XML from the cache file to create a series of variables. Finally, it echos out a chunk of HTML for each tweet, or an error message if there aren’t any.

<?php
/*
	Parse Twitter Feeds
	based on code from http://spookyismy.name/old-entries/2009/1/25/latest-twitter-update-with-phprss-part-three.html
	and cache code from http://snipplr.com/view/8156/twitter-cache/
	and other cache code from http://wiki.kientran.com/doku.php?id=projects:twitterbadge
*/
function parse_cache_feed($usernames, $limit) {
	$username_for_feed = str_replace(" ", "+OR+from%3A", $usernames);
	$feed = "http://search.twitter.com/search.atom?q=from%3A" . $username_for_feed . "&rpp=" . $limit;
	$usernames_for_file = str_replace(" ", "-", $usernames);
	$cache_file = dirname(__FILE__).'/cache/' . $usernames_for_file . '-twitter-cache';
	$last = filemtime($cache_file);
	$now = time();
	$interval = 600; // ten minutes
	// check the cache file
	if ( !$last || (( $now - $last ) > $interval) ) {
		// cache file doesn't exist, or is old, so refresh it
		$cache_rss = file_get_contents($feed);
		if (!$cache_rss) {
			// we didn't get anything back from twitter
			echo "<!-- ERROR: Twitter feed was blank! Using cache file. -->";
		} else {
			// we got good results from twitter
			echo "<!-- SUCCESS: Twitter feed used to update cache file -->";
			$cache_static = fopen($cache_file, 'wb');
			fwrite($cache_static, serialize($cache_rss));
			fclose($cache_static);
		}
		// read from the cache file
		$rss = @unserialize(file_get_contents($cache_file));
	}
	else {
		// cache file is fresh enough, so read from it
		echo "<!-- SUCCESS: Cache file was recent enough to read from -->";
		$rss = @unserialize(file_get_contents($cache_file));
	}
	// clean up and output the twitter feed
	$feed = str_replace("&amp;", "&", $rss);
	$feed = str_replace("&lt;", "<", $feed);
	$feed = str_replace("&gt;", ">", $feed);
	$clean = explode("<entry>", $feed);
	$clean = str_replace("&quot;", "'", $clean);
	$clean = str_replace("&apos;", "'", $clean);
	$amount = count($clean) - 1;
	if ($amount) { // are there any tweets?
		for ($i = 1; $i <= $amount; $i++) {
			$entry_close = explode("</entry>", $clean[$i]);
			$clean_content_1 = explode("<content type=\"html\">", $entry_close[0]);
			$clean_content = explode("</content>", $clean_content_1[1]);
			$clean_name_2 = explode("<name>", $entry_close[0]);
			$clean_name_1 = explode("(", $clean_name_2[1]);
			$clean_name = explode(")</name>", $clean_name_1[1]);
			$clean_user = explode(" (", $clean_name_2[1]);
			$clean_lower_user = strtolower($clean_user[0]);
			$clean_uri_1 = explode("<uri>", $entry_close[0]);
			$clean_uri = explode("</uri>", $clean_uri_1[1]);
			$clean_time_1 = explode("<published>", $entry_close[0]);
			$clean_time = explode("</published>", $clean_time_1[1]);
			$unix_time = strtotime($clean_time[0]);
			$pretty_time = relativeTime($unix_time);
			?>
				<blockquote>
					<p class="tweet">
						<?php echo $clean_content[0]; ?>
						<br /><small>
							<?php echo $pretty_time; ?>
						</small>
					</p>
				</blockquote>
			<?php
		}
	} else { // if there aren't any tweets
		?>
			<blockquote>
				<p class="tweet">
					I have been terribly busy recently shoveling pixels and clearing out the tubes that make up the Internet, so I haven't had a chance to tweet recently. I am truly very sorry about this, so with just a bit more prodding I'll update as soon as possible.
				</p>
			</blockquote>
		<?php
	}
}
?>

You’ll notice that I’m creating more variables than I actually need, noticeably the ones for the user names. On the Pop Art blog, we’re always showing just one person’s tweets at a time, but the code is built to allow you to pass a list of twitter accounts, and it’ll pull them all in. We used that code on another website, and I just left it in place here in case I wanted to use it at some point in the future. Since the variables already exist, I would just need to add them to the output HTML and they would show up.

Which brings me to the final problem I ran into. Ryan’s script uses the Twitter search API, which is great because it gives you the option of pulling in multiple twitter accounts. The downside of the search API is that it will only return recent tweets (the documentation says 7 days, but it looks like it actually returns two weeks).

I did some digging into the API documentation, and there’s no way around this. Twitter has two APIs, the search API and the REST API. The search API is more full-featured, including search operators and automatic link highlighting, with the downside that it only searches recent tweets. The REST API will return all tweets for a user, but it won’t highlight links, merge multiple twitter feeds, and worst of all, it requires a login.

Given those restrictions, I left the code using the search API, despite the restriction. To make the best of the situation, we wrote a funny error message for users with no tweets, and asked everyone linking their Twitter account to post at least once a week.

Note: This was originally posted on my work blog, and I’m re-posting it here for archival purposes.
Edit 11/22/2009: Turns out there was some sort of problem with the code in this post. I’ve updated it, and it seems to be working, but if you’re having any trouble with the code that you copy out of the post, you can try downloading the files directly here: twitter.php and time.php.

49 thoughts on “How to Get Your Most Recent Twitter Posts Using PHP with Caching

  1. Awesome! I’m working on the same, however I need to display the last tweets for several different people on the same page. Any thoughts on how I could use this to make that work?

  2. Sure thing! When you call the function in your PHP for a single person, it’ll probably look like this:


    <?php
    parse_cache_feed(spaceninja, 4)
    ?>

    That’ll get the last four tweets from spaceninja. Now if you use something like this instead:


    <?php
    $usernames = "popartinc spaceninja";
    $limit = "1"; // Number of tweets to pull in
    parse_cache_feed( $usernames, $limit );
    ?>

    That will get the most recent tweet from each user in the list — in this case, spaceninja and popartinc.

    Hope that helps!

    • Hi.
      I have added the above code and it seems to work.
      However if i set the limit to 1 i only get one tweet.
      If i set it to 3 i get the 3 latest tweets from the users in the list.
      But usually those 3 are from the same user. The other users dont update that often.
      Is there a way to display the latest tweet from 3 different users?

      • Sorry, but that’s exactly how the program was intended to work. What it does is ask twitter for the most recent tweets from those three users. It comes back in a single list, sorted by date.

        You could do this yourself by running three instances of the script, each one loading a single tweet from a single user, but if you tell it to load three users, it will just give you the most recent tweets, regardless of author.

  3. Pingback: Adding a twitter feed to your website | WebZooki

  4. Hi.. thanks for the code, but I am having trounle with it.. I have downloaded the files from your 11/2009 edit… when I do this the tweets appear correctly… but it always says ‘over 40 years ago’ for posted info… if I add ‘$time = time();’ as the first line of the relativeTime function then all the posts say posted 2 hours ago no matter when they were posted… the cache file is being created properly.. I just don’t know why this isn’t working. Any ideas?

    • Hi Steve,
      without seeing your site or code, I can’t say for sure what’s wrong, so here’s a few things to check – sorry if they’re a bit basic.

      1) are both the relativeTime function and the tweets function being loaded correctly?
      2) is the relativeTime function before the tweets function in the source code?
      3) do you have any javascript errors?
      4) what version of PHP are you running (don’t think this code is anything fancy, but if you’re using a very old version, it might be a problem)

  5. Thanks Scott… nothing is ever too basic for me :)

    The site is a test site that is being created… here http://www.standupsites.com/Bert2010/Test6.php is the site…

    To answer your questions:
    #1 I don’t know how to check this.
    #2 Yes.. I have the relativeTime function at the very top of my code.
    #3 No javascript errors
    #4 Current PHP version: 4.3.11

    I can paste the code here if you want, wasn’t sure if you want it.

    Thanks,
    Steve

    • Hi Steve,
      Sorry for the delay, I’ve been sick. It looks like your code might have gotten messed up when you pasted it in. I think I found the answer, but if this doesn’t help, try emailing your code to me – fake-scott (at) this domain.

      From your code, I saw two problems:

      1) You added a line that says $time = time(); in the relativeTime() function. This is what’s causing all the tweets to say two hours ago – essentially, you’re telling the relativeTime() function to ignore the time that’s passed in, so that will have to come out.

      2) It looks like the two functions got mashed together a bit. Your code looks like this:

      $years = floor($delta / DAY / 365);
      return $years $interval) ) {
      // cache file doesn't exist, or is old, so refresh it
      $cache_rss = file_get_contents($feed);

      That looks like the last few lines of the relativeTime() function and the first several lines of the parse_cache_feed() function are missing, which would cause problems.

      Again, though, if I’ve got it wrong, email me your code.
      - Scott

  6. I took your code, as is, put an include file for the time.php into the twitter.php and added the funcation call and this is what I get back. Any ideas?

    Warning: filemtime() [function.filemtime]: stat failed for /home/content/94/5725594/html/twitterface/cache/spaceninja-twitter-cache in /home/content/94/5725594/html/twitterface/twitter.php on line 16

    Warning: fopen(/home/content/94/5725594/html/twitterface/cache/spaceninja-twitter-cache) [function.fopen]: failed to open stream: No such file or directory in /home/content/94/5725594/html/twitterface/twitter.php on line 29

    Warning: fwrite(): supplied argument is not a valid stream resource in /home/content/94/5725594/html/twitterface/twitter.php on line 30

    Warning: fclose(): supplied argument is not a valid stream resource in /home/content/94/5725594/html/twitterface/twitter.php on line 31

    I have been terribly busy recently shoveling …

    • Hi Matt,
      I don’t know exactly what that error message means, but the fopen, fwrite, and fclose bits make me think that the code is having trouble writing or reading from the cache file.

      Make sure that there’s a cache/ folder in the same directory as the PHP files, and make sure that it’s got appropriate permissions for the script to write to it (if you’re not sure, set it to 777).

      If that doesn’t work, try emailing me your code and I’ll see if I can reproduce the error. fake-scott (at) this domain.

  7. Hey Scott,

    So I found the issue I was having and am posting it here at your request.

    The issue was that every post would say “2 hours ago” regardless of when it was posted… This was happeninig on 2 different hosting accounts yet when you tried the same exact code on your server it wourkd as intended.

    What I did to correct it was:

    Changed the line that sets $clean_time to:
    $clean_time = explode(“Z”, $clean_time_1[1]);
    Changed the line that set’s $delta to:
    $delta = strtotime(‘+7 hours’) – $time;

    This seems to have corrected the issue for me.

    Thanks for the great code… will be using it a lot!

  8. Scott – couple of questions:

    1) If I initially set the number of tweets to show, for example, “2″, then I change it to “10″, it still only shows the initial number. How do I increase or decrease what the script shows?

    2) Where is the cache file located? I created a “cache” folder with the right permissions (777) but there’s nothing inside of it (and the script stops working if I remove it).

    I’m on a 1and1 shared server running the latest version of WordPress. Thanks!

    -Brandon

    • 1) That sounds like it’s probably a cache issue – Did it start showing the correct number later, or does it still show 2?

      2) The cache folder should be in the same directory as your PHP – in my case, I put the PHP in my theme’s functions.php file, so I added a cache directory in wp-content/themes/$THEME/cache – I’m not sure why you’re not seeing any files in there. Since the script is dying when you remove the directory, that implies you have it in the right location. If you view source on the page, there should be a comment in the twitter block that gives the status of the cache – what does it say?

      • Scott – I’ve checked the folder and it looks like there’s a cache file in there and the comment reads:

        <!-- SUCCESS: Cache file was recent enough to read from -->

        Still, the cache file only has two entries in it. Can I add to this XML and then trust that if the function says “7″, it will keep adding to the cache?

        Again, if I use another twitter ID, this doesn’t happen. Is twitter restricting the number of XML feeded items I can grab with this script? Or is the cache remembering “2″ and not allowing it to change to another number?

      • The comment reads: “SUCCESS: Cache file was recent enough to read from”. When I delete the cache file and refresh the page, it creates a new cache file but still with the original number, not the number from the function.

        Really like this script, I’d like to get it to work as intended!

        -Brandon

        • Hi Brandon,
          I’m not sure what’s going on here – I don’t think Twitter limits the number of results you can get, so changing to 7 should work just fine. I was able to change mine from 2 to 15, deleted the cache file, and it worked fine. To be clear, your code should look like this:

          $sidebar_usernames = "YOURNAME"; // Twitter accounts to display - space-separated
          $sidebar_limit = "15"; // Number of tweets to pull in
          parse_cache_feed( $sidebar_usernames, $sidebar_limit );
        • Oh, something occurs to me – are you using any of the wordpress cache plugins like SuperCache? Those would cause the kind of problems you’re seeing because they cache the code in the sidebar that talks to Twitter.

  9. For those whose hosts have allow_url_fopen = off, this code won’t work, and will constantly fail to read from twitter.

    A solution I found that works for me is to use cURL instead of file_get_contents.

    Replace $cache_rss = file_get_contents($feed); with

    $ch = curl_init();
    $timeout = 5; // set to zero for no timeout
    curl_setopt ($ch, CURLOPT_URL, $feed);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $cache_rss = curl_exec($ch);
    curl_close($ch);
  10. I was having a problem with the most recent version of this code for a while. IE had huge fits about it, and it wouldn’t Validate.

    I changed the code to loop extra information for better styling:

    $even_odd = (' odd' != $even_odd ) ? ' odd' : ' even';
    echo '<div class="tweet'.$even_odd.'"><div class="tweetPad">';
    echo '<p>' . $clean_content[0] . '<br />';
    echo '<span class="tinyText">' . $pretty_time . '</span></p>';
    echo '</div></div>';

    Since I did it with echos, I got errors in the onClicks in the links. To fix it, I changed what the PHP converts &quot; to.

    $clean = str_replace("&quot;", '"', $clean);

    fixed my problems. The code validates now, and IE will process it without throwing a fit.

  11. Hey Anna great find and thanks for sharing that! I was going to re-write the entire thing because I couldn’t figure out where the bad attribute was coming from, but that fixed it for me!

  12. Thanks for this great bit of code — after looking around at other bloated solutions around the web this one’s a great starting point for beginning to customize the feed display.

    Cheers!

  13. I’ve implemented this code and it worked great. Just what I was looking for.

    Is there a way to link @usernames or links in the tweet content itself?

  14. Sorry – I had forgotten another modification I’d made to allow 20 tweets (not time limited by 7 days).

    In the twitter.php file, I replaced this line (original):

    $feed = "http://search.twitter.com/search.atom?q=from%3A&quot; . $username_for_feed . "&rpp=" . $limit;

    With this line (mine):

    $feed = "http://twitter.com/statuses/user_timeline/&quot; . $username_for_feed . ".atom?count=" . $limit;

    It pulled in the information I wanted, but leaves usernames and site addresses unlinked. Is there a way to use the /statuses/ $feed and link the usernames and linked sites?

    http://jasonmevius.com/elevation/ (temporary address)

    • Jason – sorry, that’s the downside to using the regular status feed instead of the search one – it doesn’t auto-link anything.

      You could do it yourself, but you’d have to write some regex to auto-link stuff. Making URLs into links is easy enough, and lots of people have done it, but the usernames are trickier – you’d need to link anything that starts with an @ sign, and contains some number of characters, ending with punctuation or a space. That’s certainly possible, but it’s beyond my limited PHP abilities.

      • To anyone who’s interested, I figured out what I needed to do. I added these two lines and changed the final output to $tweetmessage.

        $tweetmessage = preg_replace("/(http:\/\/[^\s]+)/", "<a href="$1" rel="nofollow">$1</a>", $clean_content[0]);
        $tweetmessage = preg_replace("/(@[^\s]+)/", "<a href="http://twitter.com/$1&quot; rel="nofollow">$1</a>", $tweetmessage);

        The code was adapted from here.

  15. I use this after $clean_content to parse for the status URL

    $clean_link_1 = explode("", $clean_link_1[1]);

    Just my $0.02

    • I have no problem with that (and have used it on a few commercial sites myself), but bear in mind that this is unsupported, free code. If something doesn’t work for you, post a comment here, but this is a spare time project, and I can’t guarantee anything.

  16. Hey Scott,

    I got this code up and running, and it works great! I’ve got it to post the time and date of the post rather than how long ago it was posted, makes for a great news feed! my question is not about the code, but about the twitter search function. I created a new twitter account yesterday, and I’ve posted several tweets to test the function, but only one or two pop up in the search xml.
    I’ve searched for more details, but I can’t seem to find any. Is this common, or do I just need to way for my account to be more established? I’ve seen a couple posts regarding this in other forums, but no responses.
    Thanks for the great code!

  17. Hey Scott… Here may be a tough one.. What I want to do is:
    When a tweet has a link in it I want the actulal displayed link to only be the Domain Name.. the actual link should still be the full link in the tweet.

    So if the tweet is:

    Look Here: http://www.example.com/wordpress/?p=1978

    I want the tweet that is displayed to say:

    Look Here: http://www.example.com

    but when they click the link ‘www.example.com’ they will go to ‘www.example.com/wordpress/?p=1978′

    So basically I want to strip everything other than the domain name from the anchor text

    Any ideas?

    Thanks!
    Steve

    • Hi Steve,
      The bad news is that there’s no easy way to do that. Since the body of the tweet, including all the links, comes directly from Twitter, there’s no easy way to customize it.

      What you would have to do is write some sort of search-and-replace function to check the body of the tweet for a string like href=”whatever” and use a regex function to trim the URL down to just the domain.

      I don’t know how to do that off the top of my head, but hopefully that’s enough information to point you in the right direction.

      Also, this won’t solve your problem, but I’ve got a new version of this script with a slew of improvements chilling on my hard drive. I’ll be posting about the new version soon.

  18. I’m not sure why this isn’t working for me. I thought maybe I was having that fopen posted by Alex, but it still does not return anything to me.

    I’m actually interested in going after a list instead of specifying users. I think it’s easier to manage in Twitter. The atom call is:

    http://api.twitter.com/1/SCREEN_NAME/lists/LIST_NAME/statuses.atom?per_page=25

    This makes some of the top code unnecessary as you can manage the public list in Twitter. The code though is not returning anything for me. Please help.

    Here’s my working URL:
    http://api.twitter.com/1/JerseyUDL/lists/judl/statuses.atom?per_page=25

    Chris

    • Chris, what you’re describing should work perfectly, but there’s one downside: anything other than the search API won’t have the automatic links for usernames, hashtags, and URLs.

      You’ll still get all the text, but you would have to write some regex code to turn them into links by hand (see a few comments up, Jason was dealing with the same issue).

      Other than that, it should work great. You’re right, getting a list would be a neat feature. I’ll talk to my programmer buddy about how we could add that into the next version of this script.

  19. Hi Scott,

    I realise that this is a pretty old post now but I wanted to leave a comment to say thank you – this script is brilliant and does (almost) exactly what I needed from it!

    The only thing I’m having trouble with is getting it to only display ‘proper’ tweets rather than @replies as well.

    What I mean is that at the moment, I use the script to show my (one) latest tweet. Most Twitter feed implementations I’ve seen in the past don’t include tweets where I’ve replied to someone on Twitter (eg: starting with @username), but at the moment, this script does.

    I’ve been banging my head with this one for a couple of days and I’m sure it should be a really, really simple thing to filter, but I’m at a loose end.

    I don’t suppose you, or any of your readers, have any idea how it might be achieved? I fully understand if not, but any advise would be really appreciated.

    Thanks again for sharing this with us!

    John

    • John, I spent a few hours this evening going over the Twitter API docs hoping to find a way to exclude @replies, but there’s simply no way to do it through any of the Twitter APIs yet.

      I did find a post on stackoverflow explaining how to accomplish this using javascript and the stock Twitter badge, but that doesn’t really help for our PHP script.

      My programmer buddy is going to help me add this to the next version of the script, but since we’ll be filtering out @replies after the fact, there’s a chance that you’ll end up with less tweets than you were expecting (even none!)… unfortunately, as far as I can tell, there’s no magic bullet.

      • Hi Scott,

        Thank you for that – I didn’t intend for you to spend any time on it!

        One thing I had noticed (and will be exploring next) is that all of the @reply tweets start with:

        <a href="http://twitter.com/...

        So it’s probably possible to do a string-match against the first few characters of the returned tweets and discard any that match that pattern.

        It does fall foul of a couple of fringe cases though:

        1) It relies on Twitter not changing the format of their feed

        2) It also means that should you start a Tweet with a link within the Twitter domain (eg: if you linked to the ‘new Twitter’ page here http://twitter.com/newtwitter), AND you didn’t use a URL shortening service, AND it was the very first characters in your tweet, it would also get discarded.

        All limitations I reckon I could live with!

        I’m going to ask a friend of mine who’s far more into his PHP than I am to have a look, maybe it will be possible to get rid of @replies just by detecting the first few characters..

  20. Many thanks for the script. I was having ‘could not connect to twitter’ 9 times out of 10 (or so it seemed) with Twitter Widget Pro for WordPress and an unhappy client.
    Found your script and implemented it.
    Was only when I created a ‘cache’ folder did it start to work properly.
    Great work.

    • Hi, I’ve found a validation issue with links within tweets due to lack of quotation marks.
      the line:

      $clean = str_replace("&quot;", "'", $clean);

      needs to be replaced with:

      $clean = str_replace("&quot;", "\"", $clean);

      Cheers,
      James

      • good catch – found the same thing myself. Just to clarify – this is an *important* fix to pass W3C XHTML strict validation. Not fixing it leaves a small script call in hashtag links mangled with improper quoting.

  21. I’ve been trying for hours to get the profile image url from the href with no luck. Any ideas on how to grab that?

  22. Not very elegant but you can use this code straight after the for loop to get the link address of the status.

    $clean_link_1 = explode(“:”, $clean[$i]);
    $linklen = strlen($clean_link_1[2]);
    $id = substr($clean_link_1[2], 0, ($linklen – 13));
    $id = str_replace(“”, “”, $id);
    $link = “http://twitter.com/#!/$username_for_feed/statuses/$id”;

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>