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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:48:27+00:00 2026-05-23T11:48:27+00:00

This I believe has a simple explanation, I just cannot see it. I want

  • 0

This I believe has a simple explanation, I just cannot see it. I want to generate a pretty simple csv delimetered file with double quotes around field values.

As per the manual page on fputcsv(), I try to pass on the delimiter and enclosure argument explicitly to have double-quoted field values required for data import in third-party application as in function call below:

    // relevant line of codes ...
    while($row = mysql_fetch_array($result)){

        $name_pieces = "";  
        $name_pieces = explode(" ", $row['name']);  

        $numberOfPieces = count($name_pieces);

        $lastNameIndex = $numberOfPieces - 1;

        $lastname = $name_pieces[$lastNameIndex];
        $firstname = $name_pieces[0];

 }   // Line array becomes the first, second, third fields in resulting .csv output.

    $line = array( $row['username'], 
                   $row['name'], 
                   $firstname,
                   $lastname,
                   $row['description'] );

 $data[] = $line;

}        
foreach($data as $dataLine){
    if(fputcsv($fh, $dataLine, ',', '"') === false){
      die("Unable to write to csv file.");
    }
}

Following is a sample of the script’s .csv output, notice that only second and last fields are quoted.

AG,"Alan Gaulois",Alan,Gaulois,"(AG) Alan Gaulois"
COMMIS,commis,commis,commis,"(COMMIS) commis"
DU,"Denis Fargo",Denis,Fargo,"(DF) Denis Fargo"

Anyone have an idea why the fields are not all quoted? I could well have missed something on doc page, any insight appreciated!

  • 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-23T11:48:28+00:00Added an answer on May 23, 2026 at 11:48 am

    To my knowledge, yes, delimiters are only needed if there are spaces, if you need something else, consider using array_map.

    Something like:

    function surroundWithQuotes ($input)
    {
        $input = str_replace('"', '""', $input); //escaping in csv files is done by doing the same quote twice, odd
        return '"' . $input . '"';
    }
    
    foreach($data as $dataLine){
        if(fputcsv($fh, array_map("surroundWithQuotes" $dataLine),$dataLine, ',', '') === false){
          die("Unable to write to csv file.");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting a java.awt.FontFormatException: Unrecognised Font Format error, and I believe this has been
I believe this questions has been asked in some or the other way but
While I'm perfectly willing to believe that this has been asked elsewhere, I haven't
I can't believe it,this works in my other application,but in this one,which has similiar
I have a movieclip wich has a simple movement of a simple shape. This
Happy Friday! I assume somebody out there has a simple answer to this question
This is probably pretty simple for most... I have this line in Magento which
This should be a fairly simple question. Essentially, I believe there's a good chance
I've just randomly started getting this issue, and previously it has been fine up
My question I believe is pretty simple, yet I haven't found a good answer.

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.