Return to Snippet

Revision: 45413
at April 29, 2011 18:43 by global_1981


Initial Code
function linkify_twitter_status($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;
}

Initial URL
http://davidwalsh.name/linkify-twitter-feed

Initial Description
linkify twitter text status

Initial Title
Twitter Linkify (PHP)

Initial Tags
php, twitter

Initial Language
PHP