Quantcast
Viewing all articles
Browse latest Browse all 35

Answer by Oliver M Grech for Is it possible to force Excel recognize UTF-8 CSV files automatically?

Just sharing a comprehensive function that might make your life easier working with CSV files.... please note last function argument in relation to this topic

function array2csv($data, $file = '', $download = true, $mode = 'w+', $delimiter = ',', $enclosure = '"', $escape_char = "\\", $addUnicodeBom = false){    $return = false;    if ($file == '') {        $f = fopen('php://memory', 'r+');    } else {        $f = fopen($file, $mode);    }    if ($addUnicodeBom) {        $utf8_with_bom = chr(239) . chr(187) . chr(191);        fwrite($f, $utf8_with_bom);    }    foreach ($data as $line => $item) {        fputcsv($f, $item, $delimiter, $enclosure, $escape_char);    }    rewind($f);    if ($download == true) {        $return = stream_get_contents($f);    } else {        $return = true;    }    return $return;}

Viewing all articles
Browse latest Browse all 35

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>