>PHP script for latest twitter tweet in HTML

>One of my (many) projects this weekend was to sign up for twitter and then use it as a means of making micro updates to my web page. Obviously, it shouldn’t be hard, but I had a lot of details to work out, and several tickets to have my hosting service upgrade to PHP5, and install the curl library (both of which were necessary for this hack to work).

Since it’s all working now, I thought I’d share the source. This can obviously be modified, but for now, here’s the script that’s doing doing the job. Yes, bits of it were pulled from all over the web, and some of it was cobbled together by me. Obviously, you’ll need to put the correct source for the feed, which is marked below as “http://twitter.com/..####.rss”

Enjoy!



# INSTANTIATE CURL.
$curl = curl_init();

# CURL SETTINGS.
curl_setopt($curl, CURLOPT_URL, "http://twitter.com/..####.rss$
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);

# GRAB THE XML FILE.
$xmlTwitter = curl_exec($curl);

#curl_close($curl);

# SET UP XML OBJECT.
$xmlObjTwitter = simplexml_load_string( $xmlTwitter );
$item = $xmlObjTwitter -> channel -> item;
$title = substr_replace($item -> title,'',0,8);
$url = $xmlObjTwitter -> channel -> link;
echo "Anthony tweets: {$title}";

Leave a Reply

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