Start New Discussion within our Web Development Community

Hey guys, I was trying to implement a twitter feed script into my website to display my most recent tweet, and it works fine, but the links are broken. Go to to see what I mean.

Here is the script:

$username = "sfrederick1";

$prefix = "Latest Tweet: ";

$suffix = "";

$feed = "" . $username . "&rpp=1";

function parse_feed($feed) {

$stepOne = explode("<content type=\"html\">", $feed);
$stepTwo = explode("</content>", $stepOne[1]);

$tweet = $stepTwo[0];
$tweet = str_replace("&lt;", "<", $tweet);
$tweet = str_replace("&gt;", ">", $tweet);

return $tweet;


$twitterFeed = file_get_contents($feed);

echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);

Any ideas?

Personally, I'd prefer using SimpleXml (or one of the others) to easily extract the information I want from the returned xml feed.

I tried your suggested scrip, but improved a bit. I don't know why I'm getting some errors in the beginning, but the tweets load.

    $count = 5;
    @$tweet=json_decode(file_get_contents("".$count."" ));
    for ($i; $i <= $count; $i++){
        echo $tweet[($i-1)]->text;
        echo "<br />";  

Here is an image of the errors


    $count = 5;
    $tweet=json_decode(file_get_contents("".$count."" ));
    for ($i=1; $i <= $count; $i++){        
        echo "<div class='tweet'>".$tweet[($i-1)]->text."</div>";   


.tweet {
    font-size: 10px;
    -webkit-border-radius: 28px;
-moz-border-radius: 28px;
border-radius: 28px;
-webkit-box-shadow: 5px 5px 10px #696969;
-moz-box-shadow: 5px 5px 10px #696969;
box-shadow: 5px 5px 10px #696969;
text-shadow: 0px 0px 1px #87CEEB;
background-image: -moz-linear-gradient(top, #C0C0C0, #87CEFA);
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0.00, #C0C0C0), color-stop(1.0, #87CEFA));
background-color: #DDDDDD;
padding: 10px;
font-family: Verdana, Geneva, sans-serif;
color: #888888;
text-align: center;

Live at

I'm sure that there is a way to do it without echo a Div, but this way was easy for me. Don't forget to give rep points if this helps. THANKS!

This article has been dead for over six months. Start a new discussion instead.