Simple PHP app to grab Twitter status

This evening I joined twitter and immediately got mobile support and facebook integration going. Having a central place for all my status updates is great, and the fact I can update on the move is amazing too. However, I wanted this integrated with my website so people can go to mikelaming.com/status and see what I’m doing. I wrote a little bit of PHP to get the desired effect, and if anyone else wants to do the same, here’s the code. Enjoy! (This could be rewritten to use SAX which would be faster, but DOM is so easy)

<?php

$data = file_get_contents(”http://twitter.com/statuses/user_timeline/mikelaming.xml?count=20″);

$doc = new DOMDocument();
$doc->loadXML($data);

$status = array();

$main = $doc->getElementsByTagName(”status”);
foreach($main as $sub)
{
$temp = $sub->getElementsByTagName(”text”);
$status[] = $temp->item(0)->nodeValue;
}

for($i = 0; $i < count($status); $i++)
{
if($i == 0)
{
echo(”<h2>My Current Status</h2>”);
}
else if($i == 1)
{
echo(”<h2>Older…</h2>”);
}

echo(”<p>”.$status[$i].”</p>”);
}

?>

Obviously replace my username ‘mikelaming’ with yours.

UPDATE: You can see what I’ve done with this here.

Leave a Reply