Easy Tutorial
❮ Func Xml Get Current Byte Index Func String Quoted Printable Encode ❯

PHP fputcsv() Function



Definition and Usage

The fputcsv() function formats a line as CSV and writes it to an open file.

The function returns the length of the written string. If it fails, it returns FALSE.

Syntax

Parameter Description
file Required. Specifies the open file to write to.
fields Required. Specifies the array to get data from.
separator Optional. Sets the field delimiter (only one character allowed), default is a comma ( , ).
enclosure Optional. Sets the field enclosure character (only one character allowed), default is a double quotation mark ( " ).

Tips and Notes

Tip: See the fgetcsv() function.


Example

<?php
$list = array
(
    "Peter,Griffin,Oslo,Norway",
    "Glenn,Quagmire,Oslo,Norway",
);

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

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

fclose($file); ?>

❮ Func Xml Get Current Byte Index Func String Quoted Printable Encode ❯