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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:14:03+00:00 2026-06-04T17:14:03+00:00

I need to save data array to CSV file. The problem is the following:

  • 0

I need to save data array to CSV file. The problem is the following: When I open CSV file, I see that 0 row of an array is saved at the same row as a header. Also the last column of a header contains 0, i.e. ‘www0’. How to avoid this?

        header("Content-type: text/csv");
        header("Pragma: no-cache");
        saveCSV($solutionCSV);

function saveCSV($data) {
    $outstream = fopen("schedule.csv", "a");

    $headers = 'xxx, yyy, zzz, www';
    fwrite($outstream,$headers);

    function __outputCSV(&$vals, $key, $filehandler) {
        fputcsv($filehandler, $vals);
    }
    array_walk($data, "__outputCSV", $outstream);
    fclose($outstream);
}
  • 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-04T17:14:05+00:00Added an answer on June 4, 2026 at 5:14 pm

    You need a newline after the headers. Note the change from single- to double-quotes to enable escaping.

    $headers = "xxx, yyy, zzz, www\n";
    

    If this trips up Windows, use \r\n:

    $headers = "xxx, yyy, zzz, www\r\n";
    

    Alternatively, you can rely on fputcsv to write the headers, too. This is probably the safest method as it will result in a consistent format.

    $headers = array('xxx', 'yyy', 'zzz', 'www');
    fputcsv($outstream, $headers);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using db2 export to save data to a CSV file. Ultimately I need
I have an array of ushort pixel data that I need to save as
I have the following situation: I need to save data from an Intent's putExtra
I need to save some classes and data structures to a file. My first
I want to save some custom data into application configuration file and I need
I need to save multiple arrays to a text file in the following format:
When I need to save a color to core data, I simply use NSKeyedArchiever
I have huge data which is static. I need to save it within the
need to save some persistent data. the data would only contain 3 or 4
I've written a script that saves its output to a CSV file for later

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.