title: Encoding issue with PHP while writing in a .csv file
body: <p>I'm working with a php array which contains some values parsed from a previous scraping process (using <code>Simple HTML DOM Parser</code>). I can normally <code>print</code> / <code>echo</code>  the values of this array, which contains special chars <code>é,à,è</code>, etc. <strong>BUT</strong>, the problem is the following :</p>
  <p>When I'm using <code>fwrite</code> to save values in a .csv file, some characters are not successfully saved. For example, <code>Székesfehérvár</code> is well displayed on my php view in <code>HTML</code>, but saved as <code>Sz&amp;#233;kesfeh&amp;#233;rv&amp;#225;r</code> in the <code>.csv</code> file which I generate with the php script above.</p>
  <p>I've already set-up several things in the php script :</p>
  <ul>
  <li>The page I'm <strong>scraping</strong> seems to be utf-8 encoded</li>
  <li>My PHP script is also declared as utf-8 in the header</li>
  <li>I've tried a lot of <code>iconv</code> and <code>mb_encode</code> methods in different places in the code</li>
  <li><strong>NOTE</strong> that when I'm make a JS console.log of my php array, using json_encode, the characters are also broken, maybe linked to the original encoding of the page I'm scraping?</li>
  </ul>
  <p>Here's a part of the script, it is the part who is writing values in a <code>.csv</code> file</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php 
  
  $data = array(
              array(&quot;item1&quot;, &quot;item2&quot;), 
              array(&quot;item1&quot;, &quot;item2&quot;),
              array(&quot;item1&quot;, &quot;item2&quot;),
              array(&quot;item1&quot;, &quot;item2&quot;)
              // ...
  );
  
  //filename
  $filename = 'myFileName.csv';
  
  foreach($data as $line) {
      $string_txt = &quot;&quot;; //declares the content of the .csv as a string
      foreach($line as $item) {
          //writes a new line of the .csv
          $line_txt = &quot;&quot;;
          //each line of the .csv equals to the values of the php subarray, tab separated
          $line_txt .= $item . &quot;\t&quot;;
      }
  
      //PHP endline constant, indicates the next line of the .csv
      $line_txt .= PHP_EOL;
      
      //add the line to the string which is the global content of the .csv
      $line_txt .= $string_txt;
  }
  
  //writing the string in a .csv file 
  $file = fopen($filename, 'w+');
  fwrite($file, $string_txt);
  fclose($file);
  </code></pre>
  <p>I am currently stuck because I can't save values with accentuated characters correctly.</p>