To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
I am importing a CSV file that is generated by a Point of Sale application. Unfortunately the CSV they output does not have properly escaped quotes, so a line often looks like this:
1010, "Item Description of 14" tall tree", "Blue", $10.00, 3
The extra quote in the item description is causing problems when reading this data with PHP. There are thousands of items in the database so going through and manually removing the quotes from each item description is not a great option.
Is there a way to use regular expressions or something like that to go through the whole CSV file and escape all of the extra quotes?
The idea here is to double up any double quote that is not immediately preceded or followed by a comma. This may need to be altered if your example is accurate and there is a space after each comma.
__________________
"That's what the gods are! An answer that will do! Because there's food to be caught and babies to be born and life to be lived and so there is not time for big, complicated, and worrying answers! Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." -- from Nation, by Terry Pratchett freelancer.internet.com Email me
Works flawlessly (you were right, my example was wrong, no spaces after commas). Thanks very much for your help. Time for me to spend a day learning to use regular expressions!
Works flawlessly (you were right, my example was wrong, no spaces after commas). Thanks very much for your help. Time for me to spend a day learning to use regular expressions!
If you master it in a day, I'll be impressed.
__________________
"That's what the gods are! An answer that will do! Because there's food to be caught and babies to be born and life to be lived and so there is not time for big, complicated, and worrying answers! Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." -- from Nation, by Terry Pratchett freelancer.internet.com Email me