如何删除行开头的csv文件中的ÿþ字符?

时间:2015-02-17 08:49:07

标签: php csv special-characters export-to-csv

$filename = empty($filename) ? time().'.csv' : $filename.'.csv';
$data = chr(255) . chr(254) . mb_convert_encoding($data, 'UTF-16LE', 'UTF-8');
header("Content-type:application/csv");
header("Expires: 0");
header("Cache-Control: must-revalidate");
header('Content-Disposition: attachment; filename=' . $filename);
echo $data;
exit;

当我导出到csv时,我得到的输出如下:“ÿþ”。所以我需要删除这个字符我该怎么做。

1 个答案:

答案 0 :(得分:0)

试试这个:

$filename = empty($filename) ? time().'.csv' : $filename.'.csv';
$data = chr(255) . chr(254) . mb_convert_encoding($data, 'UTF-16LE', 'UTF-8');
$cleanedData = str_replace ( "ÿþID", "" ,  $data);
header("Content-type:application/csv");
header("Expires: 0");
header("Cache-Control: must-revalidate");
header('Content-Disposition: attachment; filename=' . $filename);
echo $cleanedData;
exit;