Export DB table to Excel UTF8 problem
-
Hi everyone,
i have one problem with Export DB table to Excel with UTF8 encoding.
when i add
echo pack(“CCC”,0xef,0xbb,0xbf);
all my columns are in one. Without this command my excel is not in UTF8
function ns_contact_form_csv_pull() { global $wpdb; $table = $wpdb->prefix.'registred_players';// table name $file = 'wcgt_prihlaseni_hraci_csv'; // xls file name $command = "SELECT * FROM $table ORDER BY kod DESC"; $nieco = $wpdb->get_results($command); $data = array(); $i = 0; foreach($nieco as $zaznam) { $i++; $data[$i]=array("Meno" => $zaznam->meno, "Priezvisko" => $zaznam->priezvisko, "Domovsky klub" => $zaznam->domovsky_klub); } function cleanData(&$str) { $str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $str); if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; } // file name for download $filename = "wcgt_registrovany" . date('Ymd') . ".xls"; header("Content-Disposition: attachment; filename=\"$filename\""); header( "Content-type: application/vnd.ms-excel; charset=UTF-8" ); echo pack("CCC",0xef,0xbb,0xbf); // WHEN I REMOVED IT UTF-8 WASNT WORK $flag = false; foreach($data as $row) { if(!$flag) { // display field/column names as first row echo implode("\t", array_keys($row)) . "\n"; $flag = true; } array_walk($row, __NAMESPACE__ . '\cleanData'); echo implode("\t", array_values($row)) . "\n"; } exit; } add_action('wp_ajax_csv_pull','ns_contact_form_csv_pull'); ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Export DB table to Excel UTF8 problem’ is closed to new replies.