I have this code:
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
// output the column headings
fputcsv($output, array('שדה 1', 'שדה 2', 'שדה 3'));
include('config.php');
$id = 2;
$sql = "SELECT name FROM shoes WHERE event_id = '$id'";
$result = mysqli_query($connection,$sql);
// loop over the rows, outputting them
while ($row = mysqli_fetch_assoc($result)) fputcsv($output, $row);
The first line is ok, I get "שדה 1', 'שדה 2', 'שדה 3" but the information from my db I get like this: "׳“׳•׳¨ ׳‘׳ ׳–׳§"
Why it's not in Hebrew?
You can get it here: https://eventpay.co.il/1.php
Here my config file:
defined('DB_HOST')? null : define('DB_HOST', 'localhost');
defined('DB_USER')? null : define('DB_USER', '***');
defined('DB_PASS')? null : define('DB_PASS', '***');
defined('DB_NAME')? null : define('DB_NAME', '***');
$connection = mysqli_connect(DB_HOST ,DB_USER ,DB_PASS ,DB_NAME);
if (mysqli_connect_errno($connection)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
mysqli_set_charset($connection, "utf8");
As you can see I using "mysqli_set_charset". In addition, my all db collation is utf8_general_ci. In my others php files the details are fine (from the db).
Thank you.