1. Home
  2. Computing & Technology
  3. PHP / MySQL

Dynamic PHP Banner with your Latest Twitter Post

By Angela Bradley, About.com

1 of 3

Starting the File

Our Twitter Banner
<?php

//We are making a PNG image
header ("Content-type: image/png");

//Your Twitter Name
$name = "AboutPHP";

//This function gets your most recent twitter post for your banner
function twitter_status($twitter_id, $hyperlinks = false) {
$c = curl_init();
curl_setopt($c, CURLOPT_URL,
"http://twitter.com/statuses/user_timeline/$twitter_id.xml?count=1");
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$src = curl_exec($c);
curl_close($c);
preg_match('/<text>(.*)<\/text>/', $src, $m);
$status = htmlentities($m[1]);
if( $hyperlinks ) $status = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\">\\0</a>", $status);
return($status);
}
As you can see by the comments in the code, the first thing this does is set the headers for a PNG image. Next, you define your twitter name. Right now it is set to AboutPHP (our twitter name) so you need to change this to your own name. Next we create a function that will retrieve our latest post on twitter.
Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Step By Steps
  5. Create a Dynamic Twitter Signature with PHP - Latest Post as a Twitter Banner with PHP

©2009 About.com, a part of The New York Times Company.

All rights reserved.