Tag: Twitter
SEO Friendly PHP Twitter Script
by Mike on Jan.25, 2010, under Web Development
There are loads of scripts out there for pulling in your Twitter posts. A lot, if not most of them, base themselves heavily on JavaScript. This is bad for 3 reasons:
- People with JS disabled can’t read them
- It’s bad for your website’s search engine rank (SEO) as the search bots can’t read them
- It slows user’s browsers down (if only slightly)
I have written a very simple PHP script that pulls in your Twitter posts, and outputs them in an unordered list. Feel free to use however you like:
<?php
// Your Twitter username
$username = 'mikemike86';
$rssUrl = "http://twitter.com/statuses/user_timeline/$username.rss";
$rss = @file_get_contents($rssUrl);
if($rss){
$xml = @simplexml_load_string($rss);
if($xml !== false){
$var=true;
foreach($xml->channel->item as $tweet){
//echo $tweet->pubDate."\n";
echo ''.substr($tweet->description,(strlen($username)+2))."\n\n";
if($var){
break;
}
}
} else {
echo "Error: RSS file not valid!";
}
} else {
echo "Error: RSS file not found. Username invalid or requires authentication";
}
?>