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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:51:41+00:00 2026-06-09T15:51:41+00:00

I am using fputcsv to create a csv but the data it outputs starts

  • 0

I am using fputcsv to create a csv but the data it outputs starts on the 3rd row when i open it in excel. Why is this?

I want to create a row of column headers using fputcsv, what is the best way to do this.?

public function indexAction()
    {
        $this->outputCSV();
        //$this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')->getNavigation('passport_admin_main', array(), 'passport_admin_main_outofarea');
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        header('Content-Disposition: attachment; filename="OutOfAreaReport.csv"');
        header('Content-type: application/excel');
        readfile('OutOfAreaReport.csv');
    }

    public function outputCSV(){
        $list = array (
                array('aaa', 'saasasbbb', 'ccdddc', 'dddd')
                );
        $fp = fopen('php://output', 'w');

        foreach ($list as $fields) {
            fputcsv($fp, $fields);
        }

        fclose($fp);
    }
  • 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-09T15:51:43+00:00Added an answer on June 9, 2026 at 3:51 pm

    Because you are writing the data to php://output, I assume you are offering the file for download?

    Well, the extra new lines in the file are coming from further up your script, you have already output them.

    The most common culprit here is leading white space before the opening <?php tag in your script:

    Wrong:

    
    
    
    <?php
      // Your code here
    

    Right:

    <?php
      // Your code here
    

    EDIT Thanks to @SDC for reminding me that this also applies to any files you have included. For these files you will also need to make sure there is no trailing white space after the closing ?> tag, or preferably remove the closing tag completely, as it is not necessary for the script to work correctly.

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

Sidebar

Related Questions

I have try to write data to csv using the php function. But the
Using C#, I want to show the image in the Access column but failed
So, my code generates a CSV file using PHP's built-in fputcsv function. For the
I'm using this fputcsv code: $result = mysql_query('SELECT * FROM `mash`'); if (!$result) die('Couldn\'t
Using Entity Framework CodeFirst, how do I create a created datetime column that gets
using file_get_contents , I open an Internet URL and get the contents of this
I want to create a CSV file from the SQL query results. Till now
I have problem with writing csv file using fputcsv. Its putting the page html
Avoid default quotes from csv using fputcsv fputcsv($fp, $array, ',', ''); // OR fputcsv($fp,
Using PHP to extract data from SQL and then creating a .csv file on

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.