Question

This is my code and here i have given 3000 limit of characters for character limit. this is i am using to fetch data from csv file.

$handle = fopen('path/to/csv/file.csv', 'r');
if ($handle) {
while (($line = fgetcsv($handle, 3000, ";")) != false) {
CVarDumper::dump($line, 10, true);
}
}
fclose($handle);

but i want this should be dynamic means as like suppose if we are not sure about number of characters in line which could be increase or decrease so we need to be make sure that this will not get escaped the characters. so i want the method where i can count not all rows data but at least header line character so that i can make it dynamic at that level.

Thanks & Regards

Was it helpful?

Solution

The fgetcsv documentation states:

Omitting [the length] parameter (or setting it to 0 in PHP 5.0.4 and later) the maximum line length is not limited, which is slightly slower.

Therefore, the loop should look like:

while (($line = fgetcsv($handle, 0, ";")) != false) {
    CVarDumper::dump($line, 10, true);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top