Log in

View Full Version : Twitter latest tweet Q's



Jahova
18-10-2009, 06:26 PM
I've been using the following PHP code (not made by me) to display my latest twitter tweets on my site. I got two questions for you guys about the code today;


Is there a better and easier way to code the same thing, still in PHP
If twitter is offline, the script will stop the rest of my page from loading. Is there a way to make the rest of my page continue loading if twitter is offline, and show a message to say twitter is offline.


<?php
function getTweet($url) {
$feed = file_get_contents($url);
$xml = new SimpleXMLElement($feed);
$tweet = $xml->entry->title;
return $tweet;
}

$username = "TomSpit";
$url = "http://search.twitter.com/search.atom?q=from:".$username."&rpp=1";

echo "<a href=\"http://twitter.com/tomspit/\" onclick=\"window.open(this); return false;\">";
echo getTweet($url);
echo "</a>";
?>
All help receives a +REP. Tom.

Shibby-Shabs
18-10-2009, 11:54 PM
Sure is http://twitter.com/goodies/widgets go to "my website" then just do plain HTML or choose a design.

Dentafrice
19-10-2009, 09:44 PM
<?php
$username = "dentafrice";

$url = "http://twitter.com/statuses/user_timeline/{$username}.xml?count=1";
$get = @file_get_contents($url);

if($get) {
// did load the page..
$status = new SimpleXMLElement($get);
echo $status->status[0]->text;
}

Want to hide these adverts? Register an account for free!