1

I am trying to export into csv file. Here excel sheet insertion not correct. Only 3 rows inserted and it is not only in correct format also (some times 3 rows are inserted to one cell). Please help, what is the reason for that?

$row is a multidimensional array as follows :-

Array
(
    [0] => Array
        (
            [0] => 1
            [1] => East Midlands
            [2] => East Midlands Equestrian         
        )
   [1] => Array
        (
            [0] => 2
            [1] => East Midlands
            [2] => Leicester City
       )
)

The code used to insert into csv is :-

  $fp = fopen('/home/test/workspace/example/sites/default/files/csv/all.csv', 'w');
  $header = array('#', 'Region', 'Club Name', 'Position', 'First Name', 'Last Name', 'Address 1', 'Address 2', 'City', 'County', 'Post Code', 'Phone', 'Mobile', 'Email', 'Fax');
  fputcsv($fp, $header);
  foreach ($rows as $row) { //$row is 2D array shown above
    fputcsv($fp, $row);
  }
  fclose($fp);
pnuts
  • 58,317
  • 11
  • 87
  • 139
Rakhi Vijayan
  • 593
  • 1
  • 7
  • 12
  • How is the CSV file to be formatted? Tab or comma delimited? Are you trying to get 3 columns for each array element? – CharlesEF Sep 05 '15 at 22:20

0 Answers0