0

We have a csv file like this:

HASTANEKODU,HASTANEADI,SEHIR,BOLGE,DONEM,DONEMKODU,
1128,"SİVAS NUMUNE HASTANESİ",Sivas,"İç Anadolu Bölgesi","KASIM 2010",01

I want to get only text of headers in this csv file as array .I tried this code.

$source = 'uploads/'.$_POST['source'];

$handle = fopen($source, "r"); 

$data = array();
while( ($line = fgetcsv($handle))) {
    $data[] = $line;
}

print_r($data);

But this code get all csv fields.

How can I achive this?

Thanks

1 Answer 1

1

As the headers are the first line, then you just test whether you're reading the first line of the file, and do whatever you need different with that line

$data = array();
$headers = true;
while( ($line = fgetcsv($handle))) {
    if ($headers) {
        $headerline = $line;
        $headers = false;
    } else {
        $data[] = $line;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.