Created
November 3, 2011 17:46
-
-
Save demian85/1337169 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Create HTML anchor tags replacing URL's | |
* | |
* @param string $input | |
* @param string $target anchor target attribute | |
* @return string | |
*/ | |
function parseLinks($input, $target = '_blank') { | |
return preg_replace('#(^|\s)((?:http|https|ftp)://.+?\.[a-z]{2,3}.*?)(\s|$)#i', '$1<a href="$2" target="' . $target . '">$2</a>$3', $input); | |
} | |
function parseUsers($input, $target = '_blank') { | |
return preg_replace('#\b@([\w-]+)\b#i', '<a href="http://www.twitter.com/$1" target="' . $target . '">$1</a>', $input); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment