Created
April 12, 2012 10:06
-
-
Save mazhar266/539e57f871947e12687c to your computer and use it in GitHub Desktop.
get_twitter_status
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
<?php | |
function get_twitter_status ($twitter_id, $hyperlinks = true) | |
{ | |
$c = curl_init (); | |
curl_setopt ($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/$twitter_id.xml?count=1"); | |
curl_setopt ($c, CURLOPT_RETURNTRANSFER, 1); | |
$src = curl_exec ($c); | |
curl_close ($c); | |
preg_match ('/<text>(.*)<\/text>/', $src, $m); | |
$status = htmlentities ($m[1]); | |
if( $hyperlinks ) | |
{ | |
// The Regular Expression filter | |
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; | |
// Check if there is a url in the text | |
if (preg_match ($reg_exUrl, $status, $url)) | |
{ | |
// make the urls hyper links | |
$status = preg_replace ($reg_exUrl, "<a href=\"{$url[0]}\">{$url[0]}</a> ", $status); | |
} | |
//$status = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", '<a href="%5C%22%5C%5C0%5C%22">\\0</a>', $status); | |
} | |
return $status; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment