Skip to content

Instantly share code, notes, and snippets.

Created October 20, 2010 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/636180 to your computer and use it in GitHub Desktop.
Save anonymous/636180 to your computer and use it in GitHub Desktop.
<?php
date_default_timezone_set("Asia/Chongqing");
$feed = "http://twitter.com/statuses/user_timeline/你得数字ID.json?count=1";
function parse_feed($feed) {
$obj = json_decode($feed, true);
$a= preg_replace("/(^|[\s ])([\w]*?)((ht|f)tp(s)?:\/\/[\w]+[^ \,\"\n\r\t<]*)/is", "$1$2<a href=\"$3\">$3</a>", $obj[0]);
$a= preg_replace("/(^|[\s ])([\w]*?)((www|ftp)\.[^ \,\"\t\n\r<]*)/is", "$1$2<a href=\"http://$3\">$3</a>", $a);
$a= preg_replace("/(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+)+)/i", "$1<a href=\"mailto:$2@$3\">$2@$3</a>", $a);
$a= preg_replace("/@(\w+)/", '<a href=\"http://www.twitter.com/$1">@$1</a>', $a);
$a= preg_replace("/\#(\w+)/", '<a href=\"http://search.twitter.com/search?q=$1\">#$1</a>',$a);
$b = strtotime($obj[0]['created_at']);
$c = $a['text'] . ' at <time><a href="http://twitter.com/你得twitterID/status/' . $a['id'] . '\">' . date("n月j日, H:i", $b) . '</a></time>';
return $c;
}
$twitterFeed = file_get_contents($feed);
echo parse_feed($twitterFeed);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment