Note that there are some explanatory texts on larger screens.

plurals
  1. POwrong encoding in a csv generated by a PHP script
    text
    copied!<p>The CSV is always read by MAC users, so I guess this is a Mac problem</p> <p>I'm generating a csv file with this piece of code (thx SO :p)</p> <pre><code>&lt;?php include("../include/include.php"); $file_new_export = '../temp/new_hve_full.php'; $query = "select * from mytable"; $result = mysql_query($query) or die("Sql error : " . mysql_error()); if (!$result) die('Couldn\'t fetch records'); $i = 0; while ($row = mysql_fetch_assoc($result)) { $hve_biodiv = unserialize($row['hve_a']); $hve_ferti = unserialize($row['hve_b']); $hve_phyto = unserialize($row['hve_c']); $hve_irri = unserialize($row['hve_d']); $hve_eco = unserialize($row['hve_e']); $content[] = array_merge(array_values($hve_a), array_values($hve_b), array_values($hve_c), array_values($hve_d), array_values($hve_e)); if ($i == 0) $headers = array_merge(array_keys($hve_a), array_keys($hve_b), array_keys($hve_c), array_keys($hve_d), array_keys($hve_e)); $i++; } $fp = fopen($file_new_export, 'w'); if ($fp &amp;&amp; $result) { fwrite($fp, '&lt;?php '); fwrite($fp, 'header(\'Content-Type: application/csv; charset=iso-8859-1\');'); fwrite($fp, 'header(\'Content-Disposition: attachment; filename="export_hve.csv"\');'); fwrite($fp, 'header(\'Pragma: no-cache\');'); fwrite($fp, 'header(\'Expires: 0\');'); fwrite($fp, '?&gt;'); fputcsv($fp, $headers, ';'); foreach ($content as $fields) { fputcsv($fp, $fields, ';'); } fclose($fp); } ?&gt; </code></pre> <p>Everything works fine but I get some letters with wrong encoding, typically instead of "é" I get "È" it s close but not good...</p> <p>If the content-type and the filename are swith to an html or a txt file then all caracters are well displayed, it seems only to affect csv files, if I switch the encoding on the excel for mac to west european it still not working...</p> <p>Don't know what to do here, I m looking for a simple solution not encoding all files to utf8 or things like this cause there s a lot of data...Everything is in iso8859-1 according to the my settings (BDD/IDE/PHP encoding)...</p> <p>Thx for help</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload