Suppose I have the following line in a CSV file (I deleted the header line in this example):
"500,000",2,50,2,90000
I have a PHP script to read a CSV file, split the file into separate lines and save each line in an array called $ linearray. Then I use the foreach loop for each individual line.
Inside the foreach loop, I am breaking the string into separate variables using the following function:
$line = str_replace("'","\'",$line);
Here I insert values into separate columns in a MySQL database. The script is running. Values are inserted into the database, but I am facing a problem. I want to:
"500,000" | 2 | 50 | 2 | 90000
But I get this:
"500 | 000" | 2 | 50 | 2 | 90000
The script is not smart enough to realize that it should be missing quotation marks around quotes. Do you know how I can change my script to make sure that I get the output I'm looking for?