note 99901 added to function.fgetcsv
| From: | adam at greatbigmassive dot com | Date: | Tue, 14 Sep 2010 10:03:56 +0000 |
| Subject: | note 99901 added to function.fgetcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172535@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 69.147.83.197
Probable Submitter: 89.242.2.107
----
Manual Page -- http://www.php.net/manual/en/function.fgetcsv.php
Edit -- https://master.php.net/note/edit/99901
Del: integrated -- https://master.php.net/note/delete/99901/integrated
Del: useless -- https://master.php.net/note/delete/99901/useless
Del: bad code -- https://master.php.net/note/delete/99901/bad+code
Del: spam -- https://master.php.net/note/delete/99901/spam
Del: non-english -- https://master.php.net/note/delete/99901/non-english
Del: in docs -- https://master.php.net/note/delete/99901/in+docs
Del: other reasons-- https://master.php.net/note/delete/99901
Reject -- https://master.php.net/note/reject/99901
Search -- https://master.php.net/manage/user-notes.php