Twitter Import – Free PHP Script
As i promised earlier I have made a VERY simple script which will grab the contents of your twitter feed and then display them onto your website. This is based on an original script I found.
This code could do with a tidy up and a few extra’s but for the basic include it works as required!
Sorry wordpress decided to mess up the code, ive fixed the issues now!
<?php
// Your twitter name.
$name = "dave_berry";
// Number of tweets to pull in.
$limit = "CHANGE ME";
// Put the text you want to display BEFORE a tweet
$textBefore = "<h3>";
// Put the text you want to display AFTER a tweet
$textAfter = "</h3>";
// Do not edit below, unless you know PHP!
$feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=" . $limit;
function parse_feed($feed) {
$feed = str_replace("<", "<", $feed);
$feed = str_replace(">", ">", $feed);
$clean = explode("<content type=\"html\">", $feed);
$amount = count($clean) - 1;
for ($i = 1; $i <= $amount; $i++) {
$cleaner = explode("</content>", $clean[$i]);
echo $textBefore.$cleaner[0].$textAfter;
}
}
$twitter = file_get_contents($feed);
parse_feed($twitter);
?>
How to Use the Twitter Importer:
This is a very simple script. Below is how to edit it and make it your own:
1. Simply put in your twitter name (username) where i have placed “dave_berry”. Please remember to not remove the quotation marks!
2. Where i have put CHANGE ME (next to $limit) you need to enter in a number. This number is how many tweets will be displayed. eg: limit to 3 tweets.
3. Where i have placed <h3> (next to $textBefore) change this to what you want to have displayed before a tweet. Say for example a div style.
4. Where i have placed </h3> (next to $textAfter) change this to what you want to have displayed AFTER a tweet. Say for example the end of a div style.
Credits
Unfortunately when i discovered this code a few months back i did not make a link of where i downloaded it, so can not make a linkback. I have edited this code since download. If anyone knows where i could have downloaded this code
please email me and i will apply a link back.
Thanks
Dave!
PS: You are free to use this script anywhere, but please link back to this page!










