PHP - I want to check if the user address contains a website address

I want when the user inserts "www". in the comment textarea, the address is from "www." until the first place is replaced by a link to this address:

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

Could you tell me how to do this? (Beginner)

(sorry to post the previous question, I still don't quite understand).

Should i use preg_match_all()?

+3
source share
2 answers

Try:

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

BAH defeated me before the strike.

+1
source

Source: https://habr.com/ru/post/1721922/


All Articles