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 696759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:05:53+00:00 2026-05-14T03:05:53+00:00

I was just about to ask the same questions as the question aksed here….

  • 0

I was just about to ask the same questions as the question aksed here…. Forcing fputcsv to Use Enclosure For *all* Fields

The question was

When I use fputcsv to write out a line
to an open file handle, PHP will add
an enclosing character to any column
that it believes needs it, but will
leave other columns without the
enclosures.

For example, you might end up with a
line like this

11,”Bob “,Jenkins,”200 main st. USA
“,etc

Short of appending a bogus space to
the end of every field, is there any
way to force fputcsv to always enclose
columns with the enclosure (defaults
to a “) character?

The answer was:

No, fputcsv() only encloses the field
under the following conditions

/* enclose a field that contains a delimiter, an enclosure character, or a newline */
if (FPUTCSV_FLD_CHK(delimiter) ||
  FPUTCSV_FLD_CHK(enclosure) ||
  FPUTCSV_FLD_CHK(escape_char) ||
  FPUTCSV_FLD_CHK('\n') ||
  FPUTCSV_FLD_CHK('\r') ||
  FPUTCSV_FLD_CHK('\t') ||
  FPUTCSV_FLD_CHK(' ')
)

There is no “always enclose” option.

I need to create a CSV file will every field enclosed… What would be the best solution?

Thanks in advance…

  • 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-14T03:05:53+00:00Added an answer on May 14, 2026 at 3:05 am

    Roll your own function – its not hard:

     function dumbcsv($file_handle, $data_array, $enclosure, $field_sep, $record_sep)
     {
         dumbescape(false, $enclosure);
         $data_array=array_map('dumbescape',$data_array);
         return fputs($file_handle, 
             $enclosure 
             . implode($enclosure . $field_sep . $enclosure, $data_array)
             . $enclosure . $record_sep);
     }
     function dumbescape($in, $enclosure=false)
     {
        static $enc;
        if ($enclosure===false) {
            return str_replace($enc, '\\' . $enc, $in);
        }
        $enc=$enclosure;
     }
    

    (above is using unix style escaping)

    C.

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

Sidebar

Related Questions

i'm just curious. so i ask this particular question about SQLite. I haven't use
Did ask a question about the same problem here: Silly problem with UTF8 but
in my way of perfectionism, I'm here to ask more questions about the not-so-well-documented
all. I'm new to c++, and I want to ask a question about assign
I don't know too much about encryption, I just want to ask, which method
I use log4net in just about every code project. I was wondering what other
First of all, I'd like to ask to correct my question title if something
I want to ask a general question about the proper way to handle a
The question I want to ask is about XML namespaces. Pretty much everytime I
I want to ask a question about arraylist. In my program I defined an

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.