進出口達導出CSV文件,分隔符爲「」逗號但即時通訊有一個問題,如果欄目內容有逗號,這將打破CSV出來放時在自由辦公室計算。如何逃脫從列內容的分隔符時導出CSV
,如果任何機構可以幫助我這裏怎麼解決這個
IM高達現在
//$filename = $row['fileName'].'-ConsignmentInfo.csv';
$filename="test.csv";
$delim = ',';
$columns = array('0Product_Number', 'Product_Name', 'Alternative_Title');
echo implode($delim,$columns)."\n";
$ptr1 = DD_Db::fetch("SELECT p.pNum,p.pName,a.varcharValue FROM ds_products p left join productAttribute a on a.id=p.pID where a.attributeId= (select id FROM attribute where attributeName='alternateTitle') ");
foreach ($ptr1 as $row) {
$line = array("\"{$row['pNum']}\"","\"{$row['pName']}\"","\"{$row['varcharValue']}\"");
echo implode($delim,$line)."\n";
}
header('Content-Type: text/csv');
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header('Content-Disposition: attachment; filename='.$filename);
header('Pragma: cache');
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
exit;
如果這是Perl的我會說「用文字:: CSV」 ......不PHP有一個CSV庫中可用?車輪改造通常不是一個好主意,而CVS一代是一個相當常見的車輪。 – Quentin 2012-04-19 11:17:12