title: How to read any of the file type using php7?
body: <p>I have tried to extract the user email addresses from my server. But the problem is maximum files are <code>.txt</code> but some are <code>CSV</code> files with txt extension. When I am trying to read and extract, I could not able to read the CSV files which with TXT extension. Here is my code:  </p>
  
  <pre><code>&lt;?php
  $handle = fopen('2.txt', "r");
  while(!feof($handle)) {
          $string = fgets($handle);
     $pattern = '/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}/i';
     preg_match_all($pattern, $string, $matches);
     foreach($matches[0] as $match)
  {
  echo $match;
  echo '&lt;br&gt;&lt;br&gt;';
  }
  }
  ?&gt; 
  </code></pre>
  
  <p>I have tried to use this code for that. The program is reading the complete file which are CSV, and line by line which are Text file. There are thousands of file and hence it is difficult to identify.   </p>
  
  <p>Kindly, suggest me what I should do to resolve my problem? Is there any solution which can read any format, then it will be awesome.</p>