Skip to content

Instantly share code, notes, and snippets.

@kanduvisla
Created June 21, 2011 07:18
Show Gist options
  • Save kanduvisla/1037389 to your computer and use it in GitHub Desktop.
Save kanduvisla/1037389 to your computer and use it in GitHub Desktop.
Add links to a tweet message
<?php
$ret = preg_replace("#(^|[\n ])@([A-Za-z0-9_]+)#ise", "'\\1<a target=\"_blank\" href=\"http://www.twitter.com/\\2\" >@\\2</a>'", $text);
$ret = preg_replace("#(^|[\n ])\#([A-Za-z0-9_]+)#ise", "'\\1<a target=\"_blank\" href=\"http://twitter.com/#!/search/%23\\2\" >#\\2</a>'", $ret);
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t<]*)#ise", "'\\1<a target=\"_blank\" href=\"\\2\" >\\2</a>'", $ret);
$text = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#ise", "'\\1<a target=\"_blank\" href=\"http://\\2\" >\\2</a>'", $ret);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment