如何使用PHP创建可下载的CSV文件(除了逗号分隔)

问题描述:

Hi I want to make downloadable csv (Apostrophe ( ' ) Separated) sheet in php.

I am using code -

header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=sheet.csv');
$output = fopen('php://output', 'w');
fputcsv($output, array('header1','header2','header3'));

Now in this i am able to download csv file (comma separated but i want csv file Apostrophe ( ' ) Separated while run the page)

您好我想在php中制作可下载的csv(Apostrophe(')Separated)表。 p>

我正在使用代码 - p>

  header('Content-Type:text / csv; charset = utf-8'); 
header('Content-Disposition  :attachment; filename = sheet.csv'); 
 $ output = fopen('php:// output','w'); 
fputcsv($ output,array('header1','header2','header3'  )); 
  code>  pre> 
 
 

现在我能够下载csv文件(逗号分隔,但我想要csv文件撇号(')在运行页面时分开) p> div>

RTM

  int fputcsv ( resource $handle , array $fields [, string $delimiter = "," [, string $enclosure = '"' ]] )

so:

header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=sheet.csv');
$output = fopen('php://output', 'w');
fputcsv($output, array('header1','header2','header3'), "'");

http://www.php.net//manual/en/function.fputcsv.php

All you need to do is specify a delimiter when calling fputcsv:

fputcsv($output, array('header1','header2','header3'), "'");

If you want to then serve the file, all you'd need to do is then output it

echo file_get_contents("php://output");