Jeffski Posted September 7, 2009 Share Posted September 7, 2009 I am using fgetcsv to break apart a CSV file to extract and use the data fields in my PHP page. I have a CSV with product details in it. There are several columns in the CSV file but one of these fields contains: ...,"Toshiba 26" LCD TV",... When the data is extracted and displayed on screen the double quote which should be after 26 ends up at the end of the string - i.e.: Toshiba 26 LCD TV" I have tried to escape it and replace it but the double quote or replaced text always ends up at the end of the string. I have cut down my code to the following for debugging: $handle = fopen("products.csv", "r"); while (($data = fgetcsv($handle, 4096, ',', '"')) !== FALSE) { echo $data[0]; } The CSV I am testing on simply contains: "Toshiba 26" LCD TV" Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/173364-problem-with-fgetcsv-and-double-quotes-at-end-of-string/ Share on other sites More sharing options...
RussellReal Posted September 7, 2009 Share Posted September 7, 2009 don't use csv at all.. just use a whole bunch of serialized strings.. seperated by \x01 and then explode then unserialize each throw em into an array and pick it up where you left off Quote Link to comment https://forums.phpfreaks.com/topic/173364-problem-with-fgetcsv-and-double-quotes-at-end-of-string/#findComment-913975 Share on other sites More sharing options...
Jeffski Posted September 8, 2009 Author Share Posted September 8, 2009 I don't really have a choice as the CSV file is provided by a third party and if I want to use their data I need to use their CSV file. Quote Link to comment https://forums.phpfreaks.com/topic/173364-problem-with-fgetcsv-and-double-quotes-at-end-of-string/#findComment-914486 Share on other sites More sharing options...
RussellReal Posted September 8, 2009 Share Posted September 8, 2009 can you show like.. maybe like 1,000 characters from the csv file so I can write you up some function to help you with this Quote Link to comment https://forums.phpfreaks.com/topic/173364-problem-with-fgetcsv-and-double-quotes-at-end-of-string/#findComment-914514 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.