title: I want to read a text file and store the data in array with try-catch condition then convert it into format in php?
body: <p>I want to read the text file and read it in PHP then splits into arrays and showing data in another text file. After that, I have converted this file to format and then any user can download the converted CSV file. I have attached a file herewith <a href="http://textuploader.com/djwxd" rel="nofollow noreferrer">File.txt</a></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;title&gt;Bootstrap Example&lt;/title&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
    &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"&gt;
    &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"&gt;&lt;/script&gt;
    &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt; 
   
  &lt;div class="container"&gt;
    &lt;div class="row"&gt;
      &lt;div class="col-md-6"&gt;
        &lt;h2&gt;IRIS to ASB Conversion&lt;/h2&gt;
          &lt;div class="panel panel-default"&gt;
            &lt;div class="panel-body"&gt;
            Please Upload IRIS File &lt;br/&gt;
              &lt;br/&gt; &lt;br/&gt;
       &lt;form action="convertfile1.php" method="post" enctype="multipart/form-data"&gt;
              &lt;input type="file" name="file" id="file" &gt; &amp;nbsp; &lt;br/&gt;&lt;br/&gt;&lt;input type="submit" class="btn btn-info " value="Generate ASB Format"&gt;
      &lt;/form&gt;
            &lt;/div&gt;
          &lt;/div&gt;
           
      &lt;/div&gt;
      
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <pre><code>    &lt;?php
      $file="iris.txt";
  
      $fopen = fopen($file, 'r');
  
      $fread = fread($fopen,filesize($file));
  
      fclose($fopen);
  
      $remove = "\n";
  
      $split = explode($remove, $fread);
  
      $array[] = null;
      $tab = ",";
  
      foreach ($split as $string)
      {
          $row = explode($tab, $string);
          array_push($array,$row);
      }
      echo "&lt;pre&gt;";
      print_r($array);
      echo "&lt;/pre&gt;";
  ?&gt;
  </code></pre>
  
  <p>My code is not showing anything in an array, it is blank. How could I get data in different rows in an array with the try-catch pattern in PHP? After that file will be converted and download by any user as.CSV file in the end.</p>
  
  <p>Please help me out.</p>