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 http://sfrederick.com to see what I mean.

Here is the script:

<?
$username = "sfrederick1";

$prefix = "Latest Tweet: ";

$suffix = "";

$feed = "http://search.twitter.com/search.atom?q=from:" . $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.

PHP

<?php
    $count = 5;
    $tweet=json_decode(file_get_contents("http://api.twitter.com/1/statuses/user_timeline/atrueresistance.json?count=".$count."" ));
    for ($i=1; $i <= $count; $i++){        
        echo "<div class='tweet'>".$tweet[($i-1)]->text."</div>";   
    }
?>

css

.tweet {
    font-size: 10px;
    background-color:#E0E9EF;
    margin:5px;
    padding:5px;
    -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;
font-size:7pt;
color: #888888;
text-align: center;
}

Live at simplyaccomplished.com

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.