candice Posted September 8, 2008 Share Posted September 8, 2008 Hi all, I have a csv file that i need to import into my sql database. The csv file itself contains extra commas, that is screwing the whole app up since mysql reads the comma as a field separator. I have tried using a different field separator and also other methods such as implode/explode/str_replace etc, but it doesnt seem to work. Can anybody help me? Thanks!! Link to comment https://forums.phpfreaks.com/topic/123195-ignore-comma-in-csv-file-before-importing-into-database/ Share on other sites More sharing options...
unrelenting Posted September 8, 2008 Share Posted September 8, 2008 Is the file too large to open to edit out the extra commas with find/replace in an editor? Link to comment https://forums.phpfreaks.com/topic/123195-ignore-comma-in-csv-file-before-importing-into-database/#findComment-636292 Share on other sites More sharing options...
candice Posted September 8, 2008 Author Share Posted September 8, 2008 Yes, i have close to about a thousand rows of data. It would be inappropriate to ask the user to replace the comma manually. Link to comment https://forums.phpfreaks.com/topic/123195-ignore-comma-in-csv-file-before-importing-into-database/#findComment-636365 Share on other sites More sharing options...
aschk Posted September 8, 2008 Share Posted September 8, 2008 Firstly, why are there extra commas in it in the first place? Is it the case that the fields contain strings with commas in them, e.g. "this is , my sentence"? If that's the case then you need to alter the export to enclose the fields in inverted commas ("), then you can specify the field encapsulator in the import. This will resolve your problem... Link to comment https://forums.phpfreaks.com/topic/123195-ignore-comma-in-csv-file-before-importing-into-database/#findComment-636394 Share on other sites More sharing options...
candice Posted September 8, 2008 Author Share Posted September 8, 2008 Thanks aschk... I'll give your solution a try... Link to comment https://forums.phpfreaks.com/topic/123195-ignore-comma-in-csv-file-before-importing-into-database/#findComment-636607 Share on other sites More sharing options...
candice Posted September 10, 2008 Author Share Posted September 10, 2008 Hi aschk, I tried several ways, how do you export the csv file such that the fields are enclosed with the ("")? Thanks in advanced! Candice Link to comment https://forums.phpfreaks.com/topic/123195-ignore-comma-in-csv-file-before-importing-into-database/#findComment-638044 Share on other sites More sharing options...
lisa71283 Posted September 10, 2008 Share Posted September 10, 2008 http://us3.php.net/manual/en/function.fputcsv.php Link to comment https://forums.phpfreaks.com/topic/123195-ignore-comma-in-csv-file-before-importing-into-database/#findComment-638055 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.