Write CSV To File Without Enclosures In PHP

前端 未结 14 792
谎友^
谎友^ 2020-12-01 07:11

Is there a native function or solid class/library for writing an array as a line in a CSV file without enclosures? fputcsv will default to \" if no

相关标签:
14条回答
  • 2020-12-01 08:00
    <?php       
    
    $filename = "sample.csv";
    $handle = fopen($filename, 'w+');
    fputcsv($handle, ['column 1','column 2']);
    $data = ['sample','data'];
    
    fputs($handle, implode($data,',')."\n");
    
    // or
    
    fwrite($handle, implode($data,',')."\n");
    
    fclose($handle);
    $headers = array(
        'Content-Type' => 'text/csv',
    );
    
    0 讨论(0)
  • 2020-12-01 08:07

    chr(0) also worked for me:

     fputcsv($fp, $aLine, $sDelimiter, chr(0));
    
    0 讨论(0)
提交回复
热议问题