Skip to content

Instantly share code, notes, and snippets.

@demian85
Created November 3, 2011 17:46
Show Gist options
  • Save demian85/1337169 to your computer and use it in GitHub Desktop.
Save demian85/1337169 to your computer and use it in GitHub Desktop.
/**
* 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