Skip to content

Instantly share code, notes, and snippets.

@hmps
Created December 17, 2012 06:37
Show Gist options
  • Save hmps/4316231 to your computer and use it in GitHub Desktop.
Save hmps/4316231 to your computer and use it in GitHub Desktop.
Get latest tweet from Twitter API, insert anchor tags and return the string.
$url = "https://api.twitter.com/1/statuses/user_timeline/$userid.xml?count=1&include_rts=1callback=?";
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
$xml = simplexml_load_file($url) or die("could not connect");
foreach($xml->status as $status){
$tweet = $status->text;
}
if(preg_match($reg_exUrl, $tweet, $url)) {
return preg_replace($reg_exUrl, "<a href=\"{$url[0]}\">{$url[0]}</a>", $string);
} else {
return $tweet;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment