I want check if a string contains a variable amount of generated words. This is the code I came up with, it stores the pattern in a variable which I put in the preg_match.
Result of this code: it returns true;
$string = "What a beatiful world";
$pieces = "#\b(" . implode("|",$pieces_arr). ")\b#";
$pieces
outputs for example:
#\b(hello|you)\b#
into:
if(preg_match($pieces, $string)) {
echo "piece found in string!!";
}