I have below code that removes whole words that contain any pattern
$patterns = ["are", "finite", "get", "er"];
$string = "You are definitely getting better today";
$re = '\S*('.implode('|', $patterns).')\S*';
$string = preg_replace('#'.$re.'#', '', $string);
$string = preg_replace('#\h{2,}#', ' ', $string);
echo $string;
the output of the above code is
You today
I want to split this code into two functions so that the first function only removes whole words present in the pattern and a second function that only removes words that contain any pattern.
I expect the output of the function one that remove only whole words
You definitely getting better today (**are** is removed)
and output of the other function that remove whole word that contain pattern
You are today (**definitely getting better** are removed)