title: Remove BOM (ï»¿) from imported .csv file
body: <p>I want to delete the BOM from my imported file, but it just doesn't seem to work.</p>
  
  <p>I tried to <code>preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $file);</code> and a str_replace.<br></p>
  
  <p>I hope anybody sees what I'm doing wrong.</p>
  
  <pre><code>$filepath = get_bloginfo('template_directory')."/testing.csv";
              setlocale(LC_ALL, 'nl_NL');
              ini_set('auto_detect_line_endings',TRUE);
              $file = fopen($filepath, "r") or die("Error opening file");
              $i = 0;
              while(($line = fgetcsv($file, 1000, ";")) !== FALSE) {
                  if($i == 0) {
                      $c = 0;
                      foreach($line as $col) {
                          $cols[$c] = utf8_encode($col);
                          $c++;
                      }
                  } else if($i &gt; 0) {
                      $c = 0;
                      foreach($line as $col) {
                          $data[$i][$cols[$c]] = utf8_encode($col);
                          $c++;
                      }
                  }
                  $i++;
              }
  </code></pre>
  
  <p>-----------<br>
  SOLVED VERSION:</p>
  
  <pre><code>setlocale(LC_ALL, 'nl_NL');
  ini_set('auto_detect_line_endings',TRUE);
  require_once(ABSPATH.'wp-admin/includes/file.php' );
  
  $path = get_home_path();        
  $filepath = $path .'wp-content/themes/pon/testing.csv';
  $content = file_get_contents($filepath); 
  file_put_contents($filepath, str_replace("\xEF\xBB\xBF",'', $content));
  
  // FILE_PUT_CONTENTS AUTOMATICCALY CLOSES THE FILE
  $file = fopen($filepath, "r") or die("Error opening file"); 
  
  $i = 0;
  while(($line = fgetcsv($file, 1000, ";")) !== FALSE) {
      if($i == 0) {
          $c = 0;
          foreach($line as $col) {
              $cols[$c] = $col;
              $c++;
          }
      } else if($i &gt; 0) {
          $c = 0;
          foreach($line as $col) {
              $data[$i][$cols[$c]] = $col;
              $c++;
          }
      }
      $i++;
  }
  </code></pre>
  
  <p>I found that it removes the BOM and adjusts the file by overwriting it with the new data. The problem is that the rest of my script doesn't work anymore and I can't see why. It is a new .csv file</p>