Reputation: 152677
I need to Display Last Tweet on a web-page and want to control the styling of tweet from CSS. What is the good way to do this and Tweet should also be seen even if Javascript is disabled.
Page is on PHP server.
Edit
I just want to show last tweet on a page like this.
<div id="last-tweet">
<p>Content of tweet here</p>
</div>
Upvotes: 2
Views: 247
Reputation: 2352
Building on Jonah's answer, here's how to do the exact same but automatically link to other mentioned users and links:
$api_url = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=YOURUSERNAME';
$twitter_data = file_get_contents($api_url);
$twitter_data = json_decode($twitter_data);
$tweet = '<div id="last-tweet"><p>' . $twitter_data[0]->text . '</p></div>';
// Turn URLs into links
$tweet = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $tweet);
// Turn @replies into links
$tweet = preg_replace("/@([0-9a-zA-Z]+)/", "<a href=\"http://twitter.com/$1\">@$1</a>", $tweet);
echo $tweet;
Upvotes: 1
Reputation: 10091
With the Twitter REST API.
$api_url = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=USERNAME';
$twitter_data = file_get_contents($api_url);
$twitter_data = json_decode($twitter_data);
echo '<div id="last-tweet"><p>' . $twitter_data[0]->text . '</p></div>';
Replace USERNAME
with your username.
http://dev.twitter.com/doc#rest-api
http://php.net/file-get-contents
Upvotes: 3