Skip to content

Instantly share code, notes, and snippets.

@krutz27
Created October 4, 2013 13:32
Show Gist options
  • Select an option

  • Save krutz27/6825969 to your computer and use it in GitHub Desktop.

Select an option

Save krutz27/6825969 to your computer and use it in GitHub Desktop.
<?php
try {
$count = 6;
$tweet=json_decode(file_get_contents("http://api.twitter.com/1/statuses/user_timeline/atrueresistance.json?count=".$count."" ));
for ($i=1; $i < $count; $i++){
//Assign feed to $feed
$feed = $tweet[($i-1)]->text;
//Find location of @ in feed
$feed = str_pad($feed, 3, ' ', STR_PAD_LEFT); //pad feed
$startat = stripos($feed, '@');
$numat = substr_count($feed, '@');
$numhash = substr_count($feed, '#');
$numhttp = substr_count($feed, 'http');
$feed = preg_replace("/(http://)(.*?)/([w./&=?-,:;#_~%+]*)/", "<a href=""></a>", $feed);
$feed = preg_replace("(@([a-zA-Z0-9_]+))", "<a href="http://www.twitter.com/\1"></a>", $feed);
$feed = preg_replace('/(^|s)#(w+)/', '1<a href="http://search.twitter.com/search?q=%232">#2</a>', $feed);
echo "<div class='tweet'>".$feed. "<div class='tweet_date'>". date("M - j",strtotime($tweet[($i-1)]->created_at))."
</div></div>";
}
} catch (Exception $e) {
echo "Twitter feed is currently down, check back later.";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment