For example I have this variable:
$test = "#stack #overflow #facebook";
Now I want to make simple link with this hashtags such as:
<a href="http:/facebook.com/stack">stack</a>
<a href="http:/facebook.com/overflow">overflow</a>
<a href="http:/facebook.com/facebook">facebook</a>
I don't know which hastags stored this variable and how can I do this action simply by `str_replace?
I read this link but I can do that:
Converting my comment to answer.
You can use a preg_replace
like this to support UTF-8
:
$test = preg_replace('/#([\pL\pN_-]+)/u',
'<a href="http:/facebook.com/$1">$1</a>', $test);
Regex #[\pL\pN_-]+
matches a #
followed by 1+ unicode alphanumeric or _
or -
characters.