我将一些数据从wordpress导出到csv文件。一切正常,除了我在导出的csv的第一个单元格的开头得到这些字符从我所读到的它们是字节顺序标记(BOM),但我找不到摆脱它们的解决方案。
这是我的代码:
GLOBAL $wpdb;
global $current_user;
$query = new WP_Query(array('posts_per_page' => 1, 'post_type' => 'surf-school', 'author'=>$current_user->ID));
foreach($query->posts as $post) {
$surfschool_id = get_the_ID();
$enquiries_results = $wpdb->get_results("SELECT first_name, last_name, email FROM wp_web_leads WHERE surf_school_id = $surfschool_id");
foreach ($enquiries_results as $data) {
echo "$data->first_name, $data->last_name, $data->email\n";
}
}
$FileName = "Export_Enquiries.csv";
header('Content-Description: File Transfer');
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="' . $FileName . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
exit();