preg_replace to conditionally replace twitter hashtag and user mentions with urls
Linkify your twitter hashtags and twitter user mentions! Need to replace twitter hashtags and usernames with the actual Twitter hashtag search query links/URLs and user profile pages? Twitter Username / User Mention Preg_replace
1 |
$tweetText = preg_replace("/@([a-zA-Z0-9_]+)/", '<a href="http://www.twitter.com/$1" target="_blank">@$1</a>', $tweetText); |
Twitter Hashtag Preg_replace
1 |
$tweetText = preg_replace('/(^|\s)#(\w*[a-zA-Z_]+\w*)/', '\1#<a href="http://twitter.com/search?q=%23\2">\2</a>', $tweetText); |