I'm trying to use the following in php3 to convert all user inputed links like http://www.something.com and www.something.com to an actual url link (ie <a href="http://www.something.com" target="_blank">www.something.com</a>
So anyways the following code works for me except that if the link is something more than http://www.something.com like http://www.something.com/index.html it doesn't see anything after the / in .com and makes a link to http://www.something.com instead.
Can anyone tell me whats wrong here?
$html = preg_replace("/((http(s?):\/\/)|(www.))([\w.]+)/i", '<a href="http\3://\4\5" target="_blank">\2\4\5</a>', $html); //make html links
one more problem I just noticed with my code that I don't how to fix:
the code above matches and correctly converts http://www.something.com but once this is already a link like <a href="http://www.something.com">http://www.something.com</a> it matches it twice and screws it up. and if I modify the page again it matches it again..So i need it to not match http://www.something.com that is between > and < aswell as inside " " to prevent this.
help? :p
ok, nevermind :p..I figured it out..
$html = preg_replace("/(( http(s?):\/\/)|( www.))([\S.]+)/i", '<a href="http\3://\4\5" target="_blank">\2\4\5</a>', $html);
that does the trick! WOoHoo