title: PHP Regex to match a list of words against a string
body: <p>I have a list of words in an array. I need to look for matches on a string for any of those words.</p>
  
  <p>Example word list</p>
  
  <pre><code>company
  executive
  files
  resource
  </code></pre>
  
  <p>Example string</p>
  
  <pre><code>Executives are running the company
  </code></pre>
  
  <p>Here's the function I've written but it's not working</p>
  
  <pre><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></pre>
  
  <p>Output</p>
  
  <pre><code>0
  </code></pre>