title: PHP regex match in file content
body: <p>I have a few files I'm gathering according to their "age" (last two days) and I now need to extract text from them following a regexp pattern (in this case, the pattern it's like a microsoft product key), here's what I've done so far:</p>
  
  <pre><code>&lt;?php
  
  $files = iterator_to_array(
      new GlobIterator('/var/www/log/access.log.*', GlobIterator::CURRENT_AS_PATHNAME) );
  
  foreach ($files as $file) {
          $filelastmodified = filemtime($file);
                  if((time()-$filelastmodified) &lt; 48*3600 &amp;&amp; is_file($file))
                  {
                  $regexp = '/^[A-Z1-9]{5}(-[A-Z1-9]{5}){4}$/';
                  preg_match_all($regexp, file($file), $keys, PREG_PATTERN_ORDER);
                  }
  
  }
  print_r($keys, true);
  
  ?&gt;
  </code></pre>
  
  <p>But I'm getting an error:</p>
  
  <blockquote>
    <p>PHP Warning:  preg_match_all() expects parameter 2 to be string, array
    given in /var/www/log/keys.php on line 11</p>
  </blockquote>
  
  <p>What am I doing wrong?
  Also, I'd like to know if it possible to save those matched text strings uniquely, meaning if a key appears twice I only need it saved once into the array.
  Thanks in advance</p>