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

  • Home
  • SEARCH
  • 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 1106099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:44:20+00:00 2026-05-17T01:44:20+00:00

So, my code generates a CSV file using PHP’s built-in fputcsv function. For the

  • 0

So, my code generates a CSV file using PHP’s built-in fputcsv function.

For the delimiter, I use ',' (a comma).
For the enclosure, I use '"' (a double-quote).

However, when I try something like

fputcsv($file,array('a','b',"long string, with commas",NULL,''),',','"');

it outputs

a,b,"long string, with commas",,

but I would like it to output

"a","b","long string, with commas","",""

Is there an easy way to deal with this, or would I have to write a replacement for fputcsv?

  • 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-05-17T01:44:20+00:00Added an answer on May 17, 2026 at 1:44 am

    This is not usually a problem for CSV files.

    fputcsv puts quotes around the value if it would be ambiguous. For example,

    a,b,"long string, with commas",,
    

    is not ambiguous, but,

    a,b,long string, with commas,,
    

    is, and will in most (read: all) cases be interpreted by the CSV reader as having more than 5 fields.

    CSV parsers will accept string literals even without quotes around them.

    If you want quotes around the values anyway, the following snippet would do that. It doesn’t escape quotes inside the string – that exercise is left to the reader:

    $row = '"' . implode('", "', $rowitems) . '"';
    

    You would want to put this in a loop for all your rows.

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

Sidebar

Related Questions

My code generates a txt file using PHP's fputcsv function. For the delimiter, I
I have a script that generates a csv file using the following code: header('Content-type:
I am exporting a SQL Server table to a CSV using php (see code
I have a Web site (PHP) that generates a CSV file (text/csv) with the
Hi I'm using the following code to generate a CSV file containing data from
My code generates graph from SQL and I am using phpgraphlib for generating the
The following code generates a FileNotFoundException (using .NET 2.0): using System; using System.Collections.Generic; using
I have the following code (generates a quadratic function given the a, b, and
I'm new to PHP. I'm using the following code to generate an excel sheet
I am experimenting with loading CSV in PHP. I have a CSV file, with

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.