note 99901 deleted from function.fgetcsv by danbrown
| From: | danbrown@php.net | Date: | Tue, 14 Sep 2010 15:32:21 +0000 |
| Subject: | note 99901 deleted from function.fgetcsv by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172554@lists.php.net to get a copy of this message | ||
Note Submitter: adam at greatbigmassive dot com
----
Regarding the previous post about not handing double quotes in a .csv file.
This isn't the case, you just have to make sure you set the .csv file up correctly.
Firstly, if you set the enclosure param to be a double-quote you are saying that the .csv file you
are reading has surrounded certain data with double quotes. This is usually because the data inside
contains commas too. The double quotes around the data lets us know that those commas are part of
the data and are not defining seperate columns in the .csv file.
Now, the next problem you may face is if you also want to put double-quotes in the data. This is the
problem the previous post is facing.
All you need to do is make sure that any instance of a double quote in the data is repeated twice.
So an example of a row of data (with 4 columns) would be:
data1,data2,"This, is ""data"" 3",data4
All you do is ensure that you repeat the doublequote twice in the data area whenever it is referred
to.
The fgetcsv() function will then extract the data to be:
col1 = data1
col2 = data2
col3 = This, is "data" 3
col4 = data4
Alternatively, when you export data to a .csv file you usually get the option of selecting the
enclosure character. Just make sure it's something unique that you know you won't find in
your data. Then in fgetcsv(), just set the enclosure param to be the same character.
Simples.