I use php preg_replace()to convert any words that have a hashtag character in front of them into hyperlinks.
So, something like: #austinbecomes:<a href="/tag/austin">#austin</a>
Here is my regex.
preg_replace('/\B#(\w*[A-Za-z_]+\w*)/', '<a href="/tag/$1">$0</a>', $text);
My problem: if there are uppercase letters, the href value will keep them, but I want the href value to always be completely lowercase.
Entrance: #austin
Should not: <a href="/tag/austin">#austin</a>
It should become:<a href="/tag/austin">#austin</a>
How can I change my regex to create these results?
source
share