Question

My current code is:

$epattern[17] = "/@(\\w+)/"; 
$ereplace[17] = "<a href=viewprofile.php?username=$1><font color=royalblue><b>@\\1</b></font></a>";
$postinforawb = preg_replace($epattern,$ereplace,$postinfo);

With the above code the text will highlight blue where the @ symbol was used up to where a space has been entered. However I now also want it to include the "+" symbol in posts. So that the following would highlight blue: "@First+Second"

What am I needing to add to the replace?

Was it helpful?

Solution

This will do in your case:

$epattern[17] = "/@([\w\+]+)/"; 

But i prefer this one as you are only allowing alphabet and +:

$epattern[17] = "/@([a-zA-Z\+]+)/"; 

OTHER TIPS

$epattern[17] = "/@([\w\+]+)/";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top