Skip to content

Instantly share code, notes, and snippets.

@jasonrundell
Created June 25, 2012 02:11
Show Gist options
  • Save jasonrundell/2986032 to your computer and use it in GitHub Desktop.
Save jasonrundell/2986032 to your computer and use it in GitHub Desktop.
Birdnapper 1.1
<?php
function birdnapping($strUsername,$intShowTweets) {
$html_url="http://twitter.com/$strUsername";
$handle = @fopen($html_url, "r");
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
$content=$content.$buffer;
}
fclose($handle);
}
$content=trim($content);
$start=strpos($content,"
<div class="\&quot;section\&quot;">");
$end=strpos($content,"
<div id="\&quot;pagination\&quot;">");
$tweets=substr($content,$start,$end-$start);$arrayTweets=explode("
$tweets="";
$i=1;
while ($i
$start=strpos($arrayTweets[$i],"&gt;")+1;
$strippedTweet=substr($arrayTweets[$i],$start,strlen($arrayTweets[$i])-$start);
$tweets.="
<ul>
<li>".$strippedTweet;
$i++;
}// fix links to Twitter profiles. Twitter gives inline links
$tweets=str_replace("href=\"/","href=\"http://twitter.com/",$tweets);
return "
<div id="\&quot;birdnapping\&quot;">
\n
<ol>\n$tweets\n</ol>
\n
<div class="\&quot;follow\&quot;"><a href="\&quot;http://twitter.com/$strUsername\&quot;" target="\&quot;_blank\&quot;">Follow $strUsername »</a></div>
\n
</div>
";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment