How to add custom design twitter feed in php website?

If you are looking for twitter feed which you can customized your self then
Simple copy and paste this code in your page for twitter feed
and change the twitter username


<?php
    $username = "xyz"; // change the username
    $limit = 5;
    $feed = 'https://api.twitter.com/1/statuses/user_timeline.rss?screen_name='.$username.'&count='.$limit;
    $tweets = file_get_contents($feed);
 
$tweets = str_replace("&", "&", $tweets);
$tweets = str_replace("<", "<", $tweets);
$tweets = str_replace(">", ">", $tweets);
$tweet = explode("<item>", $tweets);
    $tcount = count($tweet) - 1;

for ($i = 1; $i <= $tcount; $i++) {
    $endtweet = explode("</item>", $tweet[$i]);
    $title = explode("<title>", $endtweet[0]);
    $content = explode("</title>", $title[1]);
$content[0] = str_replace("&#8211;", "&mdash;", $content[0]);

$content[0] = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/", '<a href="http://$2$3" target="_blank">$1$2$4</a>', $content[0]);
$content[0] = str_replace("$username: ", "", $content[0]);
$content[0] = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $content[0]);
$content[0] = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $content[0]);
    $mytweets[] = $content[0];
}

while (list(, $v) = each($mytweets)) {
@$tweetout .= "<div>$v</div>\n";
}
?>


<div style="width:300px;">
<h2>Twitter Feed</h2>
<?=$tweetout;?>
</div>
now refresh the page check your twitter feed :)


Comments