I have a CSV file that holds about 200,000 - 300,000 records. Most of the records can be separated and inserted into a MySQL database with a simple
$line = explode("\n", $fileData);
and then the values separated with
$lineValues = explode(',', $line);
and then inserted into the database using the proper data type i.e int, float, string, text, etc.
However, some of the records have a text column that includes a \n in the string. Which breaks when using the $line = explode("\n", $fileData); method. Each line of data that needs to be inserted into the database has approximately 216 columns. not every line has a record with a \n in the string. However, each time a \n is found in the line it is enclosed between a pair of single quotes (')
each line is set up in the following format:
id,data,data,data,text,more data
example:
1,0,0,0,'Hello World,0
2,0,0,0,'Hello
World',0
3,0,0,0,'Hi',0
4,0,0,0,,0
As you can see from the example, most records can be easily split with the methods shown above. Its the second record in the example that causes the problem.
New lines are only \n and the file does not include \r in the file at all.