Regular expression covert url to link (unless already is a link)

i wrote this code and i was having a problem since
it will convert this:
<a target=“_blank” rel=“nofollow” href=“”></a>
but if there was already a link:
<a href=“”></a>
it will change it like that:
<a href=“<a href=“”>”></a></a>

how can i make my code ignore the links?

function render_links($str){
		return ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a target=\\"_blank\\" rel=\\"nofollow\\" href=\\"/go/\\\\0\\">\\\\0</a>", $str);

preg (PS: EREG is deprecated.) does not have the logic built in to handle this in one line without some really awful and long patterns.

Incidentally, your system will fail to pass variables, because & and ? are not in your parsing.

Simple suggestion would be to replace all current links with a temporary value (Something like #http;//theurl# , though you should probably use a more obscure character than that. Note the semicolon instead of the colon), then do your replacement, then undo the temporary values.