Answer the question
In order to leave comments, you need to log in
How to wrap all URLs with "a" tag using regular expression in PHP?
Hello! The task is how to wrap all links in a tag using regular expressions?
<a href="адрес самой ссылки">адрес самой ссылки</a>
Answer the question
In order to leave comments, you need to log in
$text = 'Простые ссылки на сайт site.ru, на www.domain.com и на http://www.pupkin.net/';
$text = preg_replace('/((https?:\/\/)?(www)?([a-z0-9]+-?)?[a-z0-9]+\.[a-z]+)/ui', '<a href="$1">$1</a>', $text);
echo $text;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question