Using PHP how to convert csv file

cghrmauritius

i have a csv file where the header line is in row 1 not row 0 how can i convert a csv in this situation. I have seen good versions of converting a csv file where the header row is at row[0] as

function csv_to_array($filename='', $delimiter=',')
{
if(!file_exists($filename) || !is_readable($filename))
    return FALSE;

$header = NULL;
$data = array();
if (($handle = fopen($filename, 'r')) !== FALSE)
{
    while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
    {
        if(!$header)
            $header = $row;
        else
            $data[] = array_combine($header, $row);
    }
    fclose($handle);
}
return $data;
}

please can someone assist me in the situation where row[1] is the header row.

Sharry India

You can do like this :

            function csv_to_array($filename='', $delimiter=',')
            {
            if(!file_exists($filename) || !is_readable($filename))
                return FALSE;

            $header = NULL;
            $data = array();
            if (($handle = fopen($filename, 'r')) !== FALSE)
            {
                $i=0;
                while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
                {
                    if($i==0)
                    {
                      $i++;
                      continue;   //SKIP FIRST ROW
                    }
                    if(!$header)
                        $header = $row;
                    else
                        $data[] = array_combine($header, $row);
                }
                fclose($handle);
            }
            return $data;
            }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to convert a CSV file using a PHP script

From Dev

How to convert a CSV file using a PHP script

From Dev

php how to convert data from csv file?

From Dev

How to convert a text file to CSV using Bash

From Dev

How to convert XML file to CSV using Perl?

From Dev

How to convert a text file to CSV using Bash

From Dev

how to convert csv file to json using jquery and download that json file

From Dev

How do I convert a .csv file to .db file using python?

From Dev

How to convert xlsx file to csv file using shell script?

From Dev

How to Search and Rewrite a CSV file using PHP?

From Dev

How to Search and Rewrite a CSV file using PHP?

From Dev

How to upload csv file using php into mysql?

From Dev

php convert a string to csv file,

From Dev

Convert CSV to JSON using PHP

From Dev

How to convert a CSV file into a JSON script using Node.js?

From Dev

How can I convert a XLSB file to csv using python?

From Dev

How do I convert a csv file to xlsb using Python?

From Dev

How to convert csv file to json using C++

From Dev

How to convert a large Json file into a csv using python

From Dev

How to convert .xlsx file to .xml file using php?

From Dev

How to convert this text file to csv?

From Dev

Convert JSON file to a CSV file using R

From Dev

Convert an XML file to CSV file using java

From Dev

How do I convert a kml file into an image using php?

From Dev

How to Convert File size to only Megabytes using PHP

From Dev

how to convert .docx / .doc file to .pdf using php only

From Dev

How to convert image to binary string using php and file upload?

From Dev

Combining csv file using php

From Dev

PHP - Convert Tab Delimited TXT file to CSV

Related Related

HotTag

Archive