Showing your last “twit” using php

While editing my blog theme, I decided to add my last thoughts in twitter to the website. Came with a very simple php code that will get the information from the last twitter post and show it as a text line, so you can add in anywhere you want.

This is the code:

< ?php
preg_match('#(.*)#',file_get_contents('http://twitter.com/statuses/user_timeline/username.xml?count=1'), $matches);
echo $matches[0]
?>

Of course, remember to change username for your own.

Comments

  1. Hi Daniel- found you through Paul Stamatiou’s site, and since I don’t use wordpress (and thus no wordpress plugin goodness), I’m attempting your twitter method, as it appears to be platform independent. However, I put it in a php file on my site, and it just prints out the php file, not the tweet.

    php works fine on the site, though.

    the link is http://www.creativehedgehog.com/twitter.php

  2. yes I’m dumb… I removed the space between < and ? at the php, and now it doesn’t just print the contents of the php file. It doesn’t show the twitter info either though.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.