I am trying to import a CSV file to the database using https://csv.thephpleague.com/. And on my CSV file there are some comments on the right side of the CSV file i.e on certain cells with no headers.
And these cells of data which have no header at all is throwing error.
There is no issue with this error, however, the error message is not convenient as it don't give any exact message to the end user. So, I want to catch this error and alert user about the error so that the user could remove it and re-upload it.
My code look like this.
$csv = Reader::createFromPath($path, 'r');
$csv->setOutputBOM(Reader::BOM_UTF8);
$csv->addStreamFilter('convert.iconv.ISO-8859-15/UTF-8');
$csv->setHeaderOffset(0);
$csv_header = $csv->getHeader();
$sample_data = $csv->fetchOne(); //this fetchOne line is throwing this error.
How could I make this error more readable, so that the user know there are some unwanted characters on the csv file.
Example of file: