php - change separator "," in ";" from Mysqli in .csv -
this code export 1 file.csv , separated columns ","
i have little problem code. regional settings of pc not on on romanian. means separation done "," , in romanian ";" , excel takes regional settings of pc. can code make separation ";" ? thank you!
<?php // call export function exportmysqltocsv('export_csv.csv'); // export csv function exportmysqltocsv($filename = 'export_csv.csv') { $conn = dbconnection(); // check connection if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } $sql_query = "select id, firstname, lastname myguests"; // gets data database $result = $conn->query($sql_query); $f = fopen('php://temp', 'wt'); $first = true; while ($row = $result->fetch_assoc()) { if ($first) { fputcsv($f, array_keys($row)); $first = false; } fputcsv($f, $row); } // end while $conn->close(); $size = ftell($f); rewind($f); header("cache-control: must-revalidate, post-check=0, pre-check=0"); header("content-length: $size"); // output browser appropriate mime type, choose ;) header("content-type: text/x-csv"); header("content-type: text/csv"); header("content-type: application/csv"); header("content-disposition: attachment; filename=$filename"); fpassthru($f); exit; } // db connection function function dbconnection(){ $servername = "localhost"; $username = "root"; $password = ""; $dbname = "mydb"; // create connection $conn = new mysqli($servername, $username, $password, $dbname); return $conn; } ?>
you have use below, can refer put comma separator in export csv in php more.
$delimiter = ','; $enclosure = '"'; $f = fopen('php://temp', 'wt'); $first = true; while ($row = $result->fetch_assoc()) { fputcsv($f, $row, $delimiter, $enclosure); }
Comments
Post a Comment