PHP Regex to match a list of words against a string

BiofinfumnCib

New Member
I have a list of words in an array. I need to look for matches on a string for any of those words.Example word list\[code\]companyexecutivefilesresource\[/code\]Example string\[code\]Executives are running the company\[/code\]Here's the function I've written but it's not working\[code\]$matches = array();$pattern = "/^(";foreach( $word_list as $word ){ $pattern .= preg_quote( $word ) . '|';}$pattern = substr( $pattern, 0, -1 ); // removes last |$pattern .= ")/";$num_found = preg_match_all( $pattern, $string, $matches );echo $num_found;\[/code\]Output\[code\]0\[/code\]
 
Back
Top