emehrkay Posted May 16, 2007 Share Posted May 16, 2007 I have data that i want to add to a field that has a comma in it. If I do a straight input, it will mess up the column count. How do i handle this Thanks Quote Link to comment https://forums.phpfreaks.com/topic/51736-what-is-the-correct-way-to-encode-commas-for-input-into-a-csv-file/ Share on other sites More sharing options...
effigy Posted May 16, 2007 Share Posted May 16, 2007 String data is typically surrounded in double quotes: "A,B,C", 1, 2, "Bob Jones", 3, "4,5" Quote Link to comment https://forums.phpfreaks.com/topic/51736-what-is-the-correct-way-to-encode-commas-for-input-into-a-csv-file/#findComment-254829 Share on other sites More sharing options...
emehrkay Posted May 16, 2007 Author Share Posted May 16, 2007 I inputted it as a string, and it still breaks at the comma ",'". $data[$i]->address1 ."'," Quote Link to comment https://forums.phpfreaks.com/topic/51736-what-is-the-correct-way-to-encode-commas-for-input-into-a-csv-file/#findComment-254840 Share on other sites More sharing options...
effigy Posted May 16, 2007 Share Posted May 16, 2007 It sounds like the parser is substandard. What is parsing the CSV? Quote Link to comment https://forums.phpfreaks.com/topic/51736-what-is-the-correct-way-to-encode-commas-for-input-into-a-csv-file/#findComment-254843 Share on other sites More sharing options...
veridicus Posted May 16, 2007 Share Posted May 16, 2007 The CSV requires double quotes... ',"'. $data[$i]->address1 .'",' Quote Link to comment https://forums.phpfreaks.com/topic/51736-what-is-the-correct-way-to-encode-commas-for-input-into-a-csv-file/#findComment-254844 Share on other sites More sharing options...
Psycho Posted May 16, 2007 Share Posted May 16, 2007 If your data may have double quotes in it you will need to handle those too. By converting them to double-double quotes. E.g.: Data: John "The Defender" Johnson, CEO CSV Format: "John ""The Defender"" Johnson, CEO" Quote Link to comment https://forums.phpfreaks.com/topic/51736-what-is-the-correct-way-to-encode-commas-for-input-into-a-csv-file/#findComment-254849 Share on other sites More sharing options...
Barand Posted May 16, 2007 Share Posted May 16, 2007 You could make it tab-delimited and not worry about quotes and commas Quote Link to comment https://forums.phpfreaks.com/topic/51736-what-is-the-correct-way-to-encode-commas-for-input-into-a-csv-file/#findComment-254855 Share on other sites More sharing options...
emehrkay Posted May 18, 2007 Author Share Posted May 18, 2007 thanks guys, i havent tried anyof this yet, but i do know that php has built in csv parsing. I will try the fputcsv function http://www.php.net/manual/en/function.fputcsv.php Quote Link to comment https://forums.phpfreaks.com/topic/51736-what-is-the-correct-way-to-encode-commas-for-input-into-a-csv-file/#findComment-256236 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.