Funkce PHP fputcsv().
❮ Reference souborového systému PHPPříklad
Naformátujte řádek jako CSV a zapíšete jej do otevřeného souboru:
<?php
$list = array
(
array("Peter", "Griffin" ,"Oslo", "Norway"),
array("Glenn", "Quagmire", "Oslo", "Norway")
);
$file = fopen("contacts.csv","w");
foreach ($list as $line) {
fputcsv($file, $line);
}
fclose($file);
?>
Definice a použití
Funkce fputcsv() naformátuje řádek jako CSV a zapíše jej do otevřeného souboru.
Tip: Podívejte se také na funkci fgetcsv() .
Syntax
fputcsv(file, fields, separator, enclosure,
escape)
Hodnoty parametrů
Parameter | Description |
---|---|
file | Required. Specifies the open file to write to |
fields | Required. Specifies which array to get the data from |
separator | Optional. A character that specifies the field separator. Default is comma ( , ) |
enclosure | Optional. A character that specifies the field enclosure character. Default is " |
escape | Optional. Specifies the escape character. Default is "\\". Can also be an empty string ("") which disables the escape mechanism |
Technické údaje
Návratová hodnota: | Délka zapsaného řetězce při úspěchu, FALSE při neúspěchu |
---|---|
Verze PHP: | 5.1+ |
PHP Changelog: | PHP 7.4 – Parametr escape nyní přijímá prázdný řetězec pro deaktivaci mechanismu escape PHP 5.5 – Přidán parametr escape |
❮ Reference souborového systému PHP