d
Amit DhamuSoftware Engineer
 

Convert Twitter Links To URLs

1 minute read 00000 views
# Anchor Tags
$tweet = preg_replace("@(https?://([-w.]+)+(:d+)?(/([w/_.]*(?S+)?)?)?)@", "[$1]($1)", $tweet);

# @ Replies
$tweet = preg_replace("/@([0-9a-zA-Z]+)/",  "[@$1](http://twitter.com/$1)", $tweet);

# Hash Tags
$tweet = preg_replace("/#([0-9a-zA-Z]+)/", "[#$1](http://twitter.com/search?q=$1)", $tweet);