Skip to content

Instantly share code, notes, and snippets.

@pavelmaca
Created July 28, 2010 13:25
Show Gist options
  • Save pavelmaca/494497 to your computer and use it in GitHub Desktop.
Save pavelmaca/494497 to your computer and use it in GitHub Desktop.
<?php
//regex test: http://regexhero.net/tester/?id=c4b2c455-b1e3-40b8-969e-b5b8240b7324
public static function twitterify($text) {
$search = array(
'|(http://[^ ]+)|',
'/(^|[^a-z0-9_])@(\w*[a-z]+[0-9a-ž_]*)/i',
'/(^|[^a-z0-9_])#(\w*[a-z]+[0-9a-ž_]*)/i',
);
$replace = array(
'<a href="$1" title="$1">$1</a>',
'$1<a href="http://twitter.com/$2" title="$2">@$2</a>',
'$1<a href="http://twitter.com/search?q=%23$2" title="$2">#$2</a>',
);
return preg_replace($search, $replace, $text);
}
?>
@fprochazka
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment