I am working on a function to match strings in an array as individual words in the passed in array.
foreach ($word_array as $word) {
$pattern = '/\s'.$word.'\s/';
if (preg_match($pattern, $value)) {
$match = 1;
break;
}
}
The problem is that I need to pass a string into this function's foreach to create the regex pattern to match on.
I thought it could be done by setting a var outside the loop, but when I output the value of $pattern in the error_log it shows as "/\sXXX\s/", and not matching when it should.
Does anyone know why it is adding the extra backslash is being added before the \s and how to handle this?
Thanks!