title: CSV upload - parsing with SplFileObject - Remove BOM
body: <p>I have a form to upload a <code>CSV</code> file:</p>
  
  <pre><code>&lt;form method="post" action="#" enctype="multipart/form-data" accept-charset="utf-8"&gt;
    &lt;p&gt;&lt;input type="file" name="file" /&gt;&lt;/p&gt;
    &lt;p&gt;&lt;input type="submit" /&gt;&lt;/p&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>On my PHP script I do the following:</p>
  
  <pre><code>$temp = $_FILES["file"]["tmp_name"];
  
  $fobject = new SplFileObject($temp);
  $fobject-&gt;setFlags(SplFileObject::READ_CSV);
  $fobject-&gt;setCsvControl(',', '"');
  
  $data = [];
  foreach($fobject as $line) {
  $data[] = $line;
    print_r($line);
  }
  </code></pre>
  
  <p>Now there is a <code>BOM</code> in the file which shows as a </p>
  
  <blockquote>
    <p>ï»¿</p>
  </blockquote>
  
  <p>in the first <code>CSV</code> row. How can I remove this?</p>
  
  <p>I Googled and tried some solutions (<a href="https://stackoverflow.com/questions/10290849/how-to-remove-multiple-utf-8-bom-sequences-before-doctype">How to remove multiple UTF-8 BOM sequences before &quot;&lt;!DOCTYPE&gt;&quot;?</a>) but did not work.</p>
  
  <p>I can use <code>str_replace</code>, but this does not seem like a best practice to me.</p>