Answer the question
In order to leave comments, you need to log in
How to replace all tags with RegExp in PHP?
I implemented comments on my project and when quoting, I decided to enter the following tag as a name: [@UserName] , which in turn will be a link when displayed on the site.
How to replace all such tags with links in the entire text.
Example: " [@Vasya Pupkin], hello!! Do you know this dude [@Vladimir Vladimirovich]??? "
Will be displayed as:
<a href="/user/Вася Пупкин">@Вася Пупкин</a>, привет!! Ты знаешь этого чувака <a href="/user/Вася Пупкин">@Владимир Владимирович</a>???
echo preg_replace("/#(\w*[a-zA-Z_0-9]+\w*)/", "\1", $text);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question