So, I have got a preg_replace function that should replace the following pattern: Usernames with an @-character in front of them.
I have got the usernames in a multi dimensonal array called allMembers() and the regex to replace any word with a @-character and spaces around it:
/\B@[a-z-]+\s/
But how do I run the usernames contained in the array through the preg_replace function? So, just one replacement for multiple patterns.
$mentionPattern = "/\B@[ USERNAMES FROM ARRAY ALLMEMBERS HERE ]+\s/";
$mentionReplace = "<a class='userMention'>$0</a>";
preg_replace($mentionPattern, $mentionReplace, $text);
Example:
Users on my website: John, Harry, Peter
Whenever someone adds a message like "bla bla @John bla bla", the "@John" part should be replaced by something else. Replacement thus depends on the use of @ and an existing username (that I have inside an array).
altern|ative|list, don't forget to preg_quote each.