flex flex - 3 months ago 28
PHP Question

change string where find @username in php

How to replace @username in a complete string where find.

Original string :

"Hello @mike and @max how are you";

Expected result string :
"Hello <a href="#">@mike</a> and <a href="#">@max</a> how are you'

I am tried to use strpos and explode, but not got solution.

Please help any one! Thanks.


Try this regex:

$Output = preg_replace("/(\@\w+)/", "<a href='#'>$1</a>", $Original_String);