Twitter is a social netwoking phenomenon. It attracts millions of visitors everyday and it can lead to a website’s popularity. Having your twitter status on your website would be beneficial; your visitors can see your status without actually going to Twitter, which is good for people who are too lazy to open links
We’re loading the xml file from Twitter and then echoing the text using getTwitterStatus
function getTwitterStatus($userid){
$url = "http://twitter.com/statuses/user_timeline/$userid.xml?count=1";
$xml = simplexml_load_file($url) or die("could not connect");
foreach($xml->status as $status){
$text = $status->text;
}
echo $text;
}
getTwitterStatus("insert.twitter.username.here");
/*Put your twitter ID above in the brackets*/
Hope this helps!
Arjun
http://www.avn8.com
Join testking ccda course to learn more about web design. Download the testking mcts tutorial and testking mcitp guide to learn about legal issues in web designing.
Related posts:
In your code block you are missing the first and last would make it hard to use lol…are there other parts in this that should be too?
You should also include more where and how you can add this. Also how to put it into a WP layout.
You will kill your hosting CPU usage if you get over 5k visitors a day, dude! Try to put it in the cache to reduce loadtime or just using javascript
Only what I need. Thanks!
wow! thanks for sharing!
In getTwitterStatus (), did you try with that ?
echo $xml->status->text;
just a stupid question: if I want to show older tweets, I just alter the “count” attribute?
Excellent job.
Hey, this is nice!
But I make some modifications in the function, and I think others should appreciate.
Here are they:
function getTwitterStatus($userid){
$url = “http://twitter.com/statuses/user_timeline/$userid.xml?count=1″;
$xml = simplexml_load_file($url) or die(“could not connect”); //no news above
$text = utf8_decode($xml->status->text); //you need just this for your last tweet. utf8_decode is for latin characters
$text = ereg_replace(“[[:alpha:]]+://[^[:space:]]+[[:alnum:]/]”, “\“, $text); //To make links inside anchors
echo $text;
}
getTwitterStatus(“yourtwitterhere”);
It’s only that, thank you very much for your code!
I made*. Sorry about my english.
I wrote the ereg_replace wrong
here’s the right:
$text = ereg_replace(“[[:alpha:]]+://[^[:space:]]+[[:alnum:]/]”, “\“, $text);
Sorry about the mistake.
No… the comment system seems to not accept the entire code… de ereg_replace still wrong.
Hey, you can see that if your last tweet is a retweet, this code don’t work. To fix that, I made this do while estructure:
$i = 1; do { $url = "http://twitter.com/statuses/user_timeline/$userid.xml?count=$i"; $i++; $xml = simplexml_load_file($url) or die("could not connect"); $text = utf8_decode($xml->status->text);
} while (empty($text));
I hope this help someone!