★ wanayoo — archive 1999 http://www.php.net/manual/fr/function.fgetcsv.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Système de fichiers
Quick Reference
English version of this pageGerman version of this pageJapanese version of this pageItalian version of this pageHungarian version of this page
Système de fichiers
* basename
* chgrp
* chmod
* chown
* clearstatcache
* copy
* delete
* dirname
* diskfreespace
* fclose
* feof
* fgetc
* fgetcsv
* fgets
* fgetss
* file
* file_exists
* fileatime
* filectime
* filegroup
* fileinode
* filemtime
* fileowner
* fileperms
* filesize
* filetype
* flock
* fopen
* fpassthru
* fputs
* fread
* fseek
* ftell
* fwrite
* set_file_buffer
* is_dir
* is_executable
* is_file
* is_link
* is_readable
* is_writeable
* link
* linkinfo
* mkdir
* pclose
* popen
* readfile
* readlink
* rename
* rewind
* rmdir
* stat
* lstat
* symlink
* tempnam
* touch
* umask
* unlink
Manual: fgetcsv
View the source code for this pageSearch the site



Previous page
 fgetc
 Updated
Sun, 06 Aug 2000
fgets 
Next page


fgetcsv

(PHP3 >= 3.0.8, PHP4 )

fgetcsv --  Renvoie la ligne courante sur laquelle se trouve le pointeur du fichier et cherche dans le résultat les champs CSV

Description

array fgetcsv (int fp, int length [, string delimiter])

Identique à fgets() mais fgetcsv() analyse la ligne qu'il lit et recherche les champs CSV, qu'il va retourner dans un tableau les contenant. Le délimiteur de champs delimiter est la virgule, à moins que vous ne fournissiez un troisième argument.

fp doit être un pointeur valide, et avoir été correctement ouvert par fopen(), popen(), ou fsockopen().

length doit être plus grand que la plus grande ligne trouvée dans un fichier CSV (en comptant les caractères de fin de ligne).

fgetcsv() retourne FALSE en cas d'erreur, ou en cas de fin du fichier.

Note : une ligne vide dans un fichier CSV sera retournée dans le tableau comme une chaîne vide, et ne sera pas traitée comme une erreur.

Exemple 1. Exemple avec Fgetcsv() une ligne vide dans un fichier CSV sera retournée dans le tableau comme une chaîne vide, et ne sera pas traitée comme une erreur.


$row = 1;
$fp = fopen ("test.csv","r");
while ($data = fgetcsv ($fp, 1000, ",")) {
    $num = count ($data);
    print "<p> $num champs dans la ligne $row: <br>";
    $row++;
    for ($c=0; $c<$num; $c++) {
        print $data[$c] . "<br>";
    }
}
fclose ($fp);
     

User Contributed Notes: fgetcsv


quito@puc.cl
09-Feb-2000 05:15
I have a problem with this function "fgetcsv".
I can do: fgetcsv(int fp, int lengt), but if I try to use delimiter parameter the
php3 said that I have a count parameter error. Just it is succesful with two
first parameters.

Does Somebody knows a solution?

quito.



cleong@organic.com
24-Mar-2000 05:40
Methink the third parameter was added in a later version. I tried calling the function with three parameter in PHP/3.0.15 and it worked fine.


poc@baden-online.de
04-Apr-2000 07:36
fgetcsv() seems to ignore zero-length fields when working with tabs as separators (3.0.12).
Instead work around this with fgets() and do an explode() afterwards, this gets you the right thing.



gsims@pavtech.co.nz
18-Jul-2000 03:05
fgetcsv will break a field enclosed in quotes, if it contains the delimitter. Is their any way to escape the delimitter if you want it as part of the field?


gsims@pavtech.co.nz
18-Jul-2000 03:08
Oops. Ignore that last note, re Quoted fields. I was wrong. My code was screwed up.


 About Notes


Previous page
 fgetc
 Updated
Sun, 06 Aug 2000
fgets 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.