views:

76

answers:

2

I want that whenver a user inserts "www." in a comment textarea, the address from "www." until the first space will be a replaced with a link to that address:

"I love www.google.com"
turns into
"I love <a href="www.google.com">www.google.com</a>"

Can you please tell me how to do this? (newbie)

(sorry for posting the earlier question I still don't quite get it).

Should I use preg_match_all()?

+8  A: 

Try:

$text = preg_replace('/(www\.[a-zA-Z0-9-]+\.[a-zA-Z\.]{2,})/', '<a href="http://\\1"&gt;\\1&lt;/a&gt;', $text);
Ozzy
+1  A: 
preg_replace('/www\.(*)\.com/',"<a href='www.$1.com'>www.$1.com</a>",$strUrl);

BAH beat me to the punch.

strubester
That assumes that it is just a .com domain :P and by using (*), your saying that anything can be a domain ^_^
Ozzy
-1 because only .com and we all know how that worked for email addresses (.co.uk email anyone?)
disown