Created
December 17, 2012 06:37
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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