iceblox Posted June 16, 2008 Share Posted June 16, 2008 Hi, I have a script that uploads a csv datafeed, how do i get around the fact that the file has , seperating text in the same column. This is line exploding the file. $cols = explode(',', trim($line)); Has anyone got ideas to help me? Link to comment https://forums.phpfreaks.com/topic/110419-upload-script/ Share on other sites More sharing options...
rhodesa Posted June 16, 2008 Share Posted June 16, 2008 if you are parsing a CSV file, save yourself the trouble and use http://us.php.net/fgetcsv Link to comment https://forums.phpfreaks.com/topic/110419-upload-script/#findComment-566498 Share on other sites More sharing options...
iceblox Posted June 16, 2008 Author Share Posted June 16, 2008 is there away of doing what i want to achieve without changing the function? As i already have something to parse the many replacements... Link to comment https://forums.phpfreaks.com/topic/110419-upload-script/#findComment-566538 Share on other sites More sharing options...
rhodesa Posted June 16, 2008 Share Posted June 16, 2008 actually....first question is: on a line of data that has a comma as text in a field, is that field being properly wrapped with double quotes? can you provide an example of a line that is giving you trouble? Link to comment https://forums.phpfreaks.com/topic/110419-upload-script/#findComment-566555 Share on other sites More sharing options...
iceblox Posted June 16, 2008 Author Share Posted June 16, 2008 I have added the feed so that you can see an example.. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/110419-upload-script/#findComment-566614 Share on other sites More sharing options...
rhodesa Posted June 16, 2008 Share Posted June 16, 2008 $cols = preg_replace("/^\"(.*)\"$/","$1",preg_split("/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/",$line)); ...but fgetscv is much better/more flexible Link to comment https://forums.phpfreaks.com/topic/110419-upload-script/#findComment-566619 Share on other sites More sharing options...
iceblox Posted June 16, 2008 Author Share Posted June 16, 2008 Thanks for the help rhodesa. Its much appreciated, the error is still there though. Is it just a case of replacing that line you gave me with the line i posted? Link to comment https://forums.phpfreaks.com/topic/110419-upload-script/#findComment-566628 Share on other sites More sharing options...
rhodesa Posted June 16, 2008 Share Posted June 16, 2008 um...should be...can you post more of your code? Link to comment https://forums.phpfreaks.com/topic/110419-upload-script/#findComment-566643 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.