How to set column limit in csv file?

Re: set column limit in csv file in php 80 80

You could use array_chunk(), for example in file.csv you have:

column1,column2,column3,column4,column5
column1,column2,column3,column4,column5
column1,column2,column3,column4,column5

And your script executes a loop:

$file = file('./file.csv');
$result = array();

foreach($file as $csv)
{
    $s = array_chunk(str_getcsv($csv), 3);
    $result[] = $s[0];
}

The $result array will return only the first three columns of each line.

Re: set column limit in csv file in php 80 80

Thank You.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.