Ok, here is the story, I was challenged to write a scrape of twitter in less than 30 lines of code and not use a library. Albeit the library would make the execution faster, and of course less lines of code, that was the challenge.
Not being shy of a challenge, I accepted and started to get after it
30 minutes later, I had my solution.....in 9 lines of code!
I won a nice veggie burger at Blue Planet! Its good to be a geek.
I love writting custom applications, and custom API’s
Want to give it a shot click here!
Sorry there are no results with the twitter handle phpCodeNinja
This is the PHP code to make this work
<?php
// Tiwtter scrape
// This function needs just one attribute, the twitter name
function getTwitterTwenty($name)
{
$name = file_get_contents("http://www.twitter.com/$name");
preg_match_all("|(<ol class=\"statuses\" id=\"timeline\">)(.*?)(<\/ol>)|", $name, $matches, PREG_SET_ORDER);
$content = '<div class="twitterResults">';
foreach ($matches as $val)
{
$content .= $val[0] . "\n";
}
$content .='</div><br><hr></hr><br>';
return $content;
}
// give the function the twitter name to get the results.
echo getTwitterTwenty('phpCodeNinja');
?>