title: Convert a list of file type, in a regular expression in PHP
body: <p><strong>I don't ask how validate upload file</strong></p>
  
  <p>I need to set a PHP regex like this: </p>
  
  <pre><code>'/\.(pdf|doc|docx)$/i'
  </code></pre>
  
  <p>from a list like this:</p>
  
  <pre><code> .pdf,.doc,.docx 
  </code></pre>
  
  <p>The goal is set the accept file types, in an upload form.</p>
  
  <p>I tried:</p>
  
  <pre><code>$filetype_arr = explode("," , ".pdf,.doc,.docx");
  $filetype_str = '/\.(';
  for ($i=0; $i &lt; count($filetype_arr) ; $i++) { 
      $filetype_ext = explode("." , $filetype_arr[$i]);
      $pipe = "";
      if ($i &lt; count($filetype_arr) - 1) $pipe = "|";
      $filetype_str .= $filetype_ext[1] . $pipe;
  }
  $filetype_str .= ')$/i';
  // $filetype_str = '/\.(pdf|doc|docx)$/i'
  
  'accept_file_types' =&gt; $filetype_str,
  </code></pre>
  
  <p>And don't works, but:</p>
  
  <pre><code>'accept_file_types' =&gt; '/\.(pdf|doc|docx)$/i',
  </code></pre>
  
  <p>Works.</p>
  
  <p><strong>EDIT:</strong>
  As title says: "I need to convert a list in a RegEx in php" ... I don't ask how validate upload file, it's not duplicate.
  This regex will be insert in a library for upload file, and I just need to set the valid extension from a dynamic list.</p>
  
  <pre><code>'accept_file_types' =&gt; '/\.(' . $myDynamicList . ')$/i',
  </code></pre>
  
  <p><strong>Simplify:</strong></p>
  
  <p>Dont works:</p>
  
  <pre><code>$validFile = '/\.(' . str_replace(',.', '|', ".pdf,.doc,.docx") . ')$/i';
  'accept_file_types' =&gt; $validFile,
  </code></pre>
  
  <p>It works:</p>
  
  <pre><code>'accept_file_types' =&gt; '/\.(pdf|doc|docx)$/i',
  </code></pre>
  
  <p>Many thanks</p>