Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7803587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:37:58+00:00 2026-06-02T01:37:58+00:00

Im up to export the CSV file, delimiter is a , comma but im

  • 0

Im up to export the CSV file, delimiter is a “,” comma but im there is a problem if column content had comma , it will break the csv out put when looking on libre office calc.

if any body can help me how to solve this

here im upto now

//$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;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:38:00+00:00Added an answer on June 2, 2026 at 1:38 am

    Just use fputcsv it takes care of escaping and producing correct csv data.

    <?php
    
    $list = array (
        array('aaa', 'bbb', 'ccc', 'dddd'),
        array('123', '456', '789'),
        array('"aaa"', '"bbb"')
    );
    
    $fp = fopen('file.csv', 'w');
    
    foreach ($list as $fields) {
        fputcsv($fp, $fields);
    }
    
    fclose($fp);
    ?>
    

    Output:

    aaa,bbb,ccc,dddd
    123,456,789
    """aaa""","""bbb"""
    

    Edit

    You can always use a combination of tmpfile to open a file that will be automatically deleted at the end of the request, write to it and then after the report is created output its content with fread. You have to use fread since tmpfile return a resource, otherwise you can use tempnam + file_get_contents but in that case you have to open the file and to cleanup after read it by yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to export csv file in php using mysql query .But when i
I have a requirement to export a dataset as a CSV file. I have
I ran bulkloader with parameters to export my bigtable to a csv file, and
I would like to export a Java Bean or ResultSet(JDBC) into a CSV file
I'm working on a feature to export search results to a CSV file to
I'm trying to export data to a csv file. It should contain a header
Is there a simple way to export a WPF DataGrid to a text file
I want to export the database to CSV file and read in MatLab. I
I have function for export data into csv file : $products = //databse query
Does anyone know how to export a CSV file from a SQLite3 database in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.