I have multiple words, I want to preg_match these words in my input string, such as:
$string = "white red green blue";
$pattern = "/red, blue/";
echo preg_match($pattern, $string);
my result is 0, Please tell me how it possible.
You can use multiple words in pattern 2 or more for preg_match, like this:
$string = "white red green blue";
$pattern = "/(red)|(blue)/";
echo preg_match($pattern, $string);
result : 1
If you still have a question about this, submit it in our Q&A community - Ask Question