Possible Duplicate:
Finetune Regex to skip tags
Currently my function looks like this. It converts plain text URLs into HTML links.
function UrlsToLinks($text){
return preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.-]*(\?\S+)?)?)?)@', '<a href="$1" target="_blank">$1</a>', $text);
}
But there are some problems. What I'm trying to do is skip existing links, the src
attribute in <img>
tags, etc.. Can't figure out what I need to modify in this function.