So, basically I have a text file with a ton of information and I'm trying to sort it so that I can put it into a database. I have been able to open it and put it into an array using the explode() function, but the problem is that the fields are comma separated as well as some of the content. For instance:
Name, Number, Keywords
Justin, 902-324-2344, "me, I, they"
So I more or less want to group the keywords together in one key of the array, but the commas are breaking that up. I do know however that the keywords are always surrounded by quotes, so I don't know if I can somehow change the code below to keep everything between quotes together, or if I need to do something else. So basically I'm wondering if I can get some assistance with a way of figuring this out.
PHP Code:
// File name
$filename = "file.txt";
// Open file an write contents to the $contents variable
$fh = fopen($filename, "r") or die ("Unable to open file.");
$contents = fread($fh, 5000);
// Close the opened file to conserve memory
fclose($fh);
// Place all of the data into a giant array.
$products_array = explode(",", $contents);
Edit: So I've decided to switch the delimeter to a pipe character which alleviates me of this problem.