【发布时间】:2015-06-17 10:51:39
【问题描述】:
我有这个代码:
// 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);
第一行没问题,我得到“שדה 1', 'שדה 2', 'שדה 3” 但是我从数据库中得到的信息是这样的:“׳“׳•׳¨ ׳'׳ ׳–׳§ "
为什么不是希伯来语?
你可以在这里得到它: https://eventpay.co.il/1.php
这是我的配置文件:
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");
如您所见,我使用“mysqli_set_charset”。 另外,我所有的数据库排序规则都是utf8_general_ci。 在我的其他 php 文件中,细节很好(来自数据库)。
谢谢。
【问题讨论】:
标签: php csv utf-8 export-to-csv hebrew