Skip to content

Instantly share code, notes, and snippets.

@mazhar266
Created April 12, 2012 10:06
Show Gist options
  • Save mazhar266/539e57f871947e12687c to your computer and use it in GitHub Desktop.
Save mazhar266/539e57f871947e12687c to your computer and use it in GitHub Desktop.
get_twitter_status
<?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