Current Location: Home> Function Categories> fputcsv

fputcsv

Format the line to CSV and write to the file pointer
Name:fputcsv
Category:File system
Programming Language:php
One-line Description:Format the line to CSV and write to an open file.

Definition and usage

fputcsv() function formats the line to CSV and writes to an open file.

This function returns the length of the written string. If an error occurs, false is returned. .

Example

 <?php
$list = array
(
"George, John, Thomas, USA" ,
"James,Adrew,Martin,USA" ,
) ;

$file = fopen ( "contacts.csv" , "w" ) ;

foreach ( $list as $line )
  {
  fputcsv ( $file , split ( ',' , $line ) ) ;
  }

fclose ( $file ) ;
?>

After the above code is executed, the CSV file will look like this:

 George, John, Thomas, USA
James Adrew Martin USA

grammar

 fputcsv ( file , fields , seperator , enclosure )
parameter describe
file Required. Specifies the open file to be written.
fields Required. Specifies an array from which data is to be obtained.
seperator Optional. Characters that specify field separators. The default is comma (,).
enclosure Optional. Characters that specify the field surrounding the character. The default is double quotes".

illustrate

fputcsv() formats a line (passed with fields array) into CSV format and writes to the file specified by the file .

Similar Functions
  • Format the line to CSV and write to the file pointer fputcsv

    fputcsv

    FormatthelinetoCSVan
  • Change the current umask umask

    umask

    Changethecurrentumas
  • Get the file owner fileowner

    fileowner

    Getthefileowner
  • Delete directory rmdir

    rmdir

    Deletedirectory
  • Determine whether the given file name is executable is_executable

    is_executable

    Determinewhethertheg
  • Determine whether the given file name is a directory is_dir

    is_dir

    Determinewhethertheg
  • Change the group to which the file belongs chgrp

    chgrp

    Changethegrouptowhic
  • Close process file pointer pclose

    pclose

    Closeprocessfilepoin