I'm trying to convert something like this:
@Username
into:
<a href="Username">Username</a>
Can't find a RegEx for it anywhere though. Any suggestions?
Thanks!
You can use the preg_replace function for this:
$str = preg_replace('/@(\w+)/', '<a href="$1">$1</a>', $str);
I would also recommend you read the documentation on regular expressions.
<img alt="@username">-- you don't want to insert a <a> tag inside another tag's attribute value. As a result, your best bet is actually to construct a proper dom tree.