Possible Duplicate:
How to add anchor tag to a URL from text input
PHP Regular expression to match keyword outside HTML tag <a>
Alright, so I am using OsTicket (email ticket system), and have converted it to use HTML format emails going both in and out. It's hacked, but it works.
Well, at the moment there is a function in there called "clickableURLS"....
function clickableurls($text) {
//Not perfect but it works - please help improve it.
$text=preg_replace('/([^(\'|")]((f|ht){1}tp(s?):\/\/)[-a-zA-Z0-9@:%_\+.~#?&;\/\/=]+[^(\'|")])/','<a href="\\1" target="_blank">\\1</a>', $text);
$text=preg_replace("/(^|[ \\n\\r\\t])([^('|\")]www\.([a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+)(\/[^\/ \\n\\r]*)*[^('|\")])/",
'\\1<a href="http://\\2" target="_blank">\\2</a>', $text);
$text=preg_replace("/(^|[ \\n\\r\\t])([^('|\")][_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}[^('|\")])/",'\\1<a href="mailto:\\2" target="_blank">\\2</a>', $text);
return $text;
}
As you can see, it basically takes a URL (searches for http or https or www) and then adds the appropriate mumbo jumbo in there.
WELL....
I now have a WYSIWYG set up.... so if a one of our techs usees the WYSIWYG to create a link the RIGHT way...which automatically creates the code.... then the clickableurls function ALSO finds the http that is already in the text and converts it AGAIN...
So I am basically trying to figure out the best way to handle that. I do want BOTH options.. and was thinking maybe doing an IF statement, but wouldnt changing the preg_replace make a bit more sense?
Any thoughts? Thanks again overflow community!