Skip to content

Instantly share code, notes, and snippets.

@Robbertdk
Created June 19, 2014 07:23
Show Gist options
  • Save Robbertdk/ef28a67575caf9dfafaf to your computer and use it in GitHub Desktop.
Save Robbertdk/ef28a67575caf9dfafaf to your computer and use it in GitHub Desktop.
Linkify Twitter JSON feed, via http://davidwalsh.name/linkify-twitter-feed
private function linkify($status_text){
// linkify URLs
$status_text = preg_replace(
'/(https?:\/\/\S+)/',
'<a href="\1">\1</a>',
$status_text
);
// linkify twitter users
$status_text = preg_replace(
'/(^|\s)@(\w+)/',
'\1@<a href="http://twitter.com/\2">\2</a>',
$status_text
);
// linkify tags
$status_text = preg_replace(
'/(^|\s)#(\w+)/',
'\1#<a href="http://search.twitter.com/search?q=%23\2">\2</a>',
$status_text
);
return $status_text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment