Show DevBest [UPDATED] Latest Twitter Post Scrip

Status
Not open for further replies.

Jo$h

Posting Freak
Jul 7, 2010
1,030
79
This is a Script written by I have made a few modifications to it, so that it also loads the avatar in a nice and easy way as well. Thanks again to Mark for doing 95% of the script ;)


ScreenShot:
PHP:
<?php
function twitter( $username )
{
  // What is the file format for your avatar?
  // jpg, png, gif
    $file_format = "jpg";
    $twitterurl = file_get_contents( "http://twitter.com/statuses/user_timeline/{$username}.xml?count=1" );
    $xml = new SimpleXMLElement( $twitterurl );
    $s = $xml->status;
    $text = $s->text;
    $twitteravatar = "http://api.twitter.com/1/users/profile_image/{$username}.{$file_format}";
  echo "<img src='{$twitteravatar}' alt='{$username}'s Twitter' style='height:30px; width: 30px;'>";
  return $text;
}
echo twitter(twitter);
?>
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
You could also do this to avoid having to user the $file_format variable you have defined in case someone doesn't have a JPG avatar so their avatar won't be displayed:

PHP:
<?php
function twitter( $username )
{
    $twitterurl = file_get_contents( "http://twitter.com/statuses/user_timeline/{$username}.xml?count=1" );
    $xml        = new SimpleXMLElement( $twitterurl );
    $status     = $xml->status->text;
    $picture    = $xml->user->profile_image_url;
    return '<img src="' . $picture . '" width="50" height="50" /> ' . $status;
}
echo twitter( "iiM4RKx" );
?>

I've not tested it, but I can't see it not working.

It's also a shorter code.
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
You could also do this to avoid having to user the $file_format variable you have defined in case someone doesn't have a JPG avatar so their avatar won't be displayed:

PHP:
<?php
function twitter( $username )
{
    $twitterurl = file_get_contents( "http://twitter.com/statuses/user_timeline/{$username}.xml?count=1" );
    $xml        = new SimpleXMLElement( $twitterurl );
    $status    = $xml->status->text;
    $picture    = $xml->user->profile_image_url;
    return '<img src="' . $picture . '" width="50" height="50" /> ' . $status;
}
echo twitter( "iiM4RKx" );
?>

I've not tested it, but I can't see it not working.

It's also a shorter code.

Would be better using JSON ;)
 
Status
Not open for further replies.

Users who are viewing this thread

Top