fputcsv

FunctionParams changed in PHP 8.1

Format line as CSV and write to file pointer.

PHP 5
PHP 7.0
Improved
PHP 7.1-7.4
PHP 8.0
Improved
PHP 8.1
Improved
PHP 8.2
PHP 8.3
PHP 8.4
Changed
PHP 8.5

fputcsv Function synopsis

fputcsv(
    $stream,
    array $fields,
    string $separator = ",",
    string $enclosure = "\"",
    string $escape = "\\",
    string $eol = "\n"
  ): int|false

Parameters

$stream
$fields

Typearray

An array of strings.

$separator

OptionalTypestringDefault value","

$enclosure

OptionalTypestringDefault value"\""

$escape

OptionalTypestringDefault value"\"

$eol

OptionalTypestringDefault value"\n"

The optional $eol parameter sets a custom End of Line sequence.

Return value

Typeint|false

Returns the length of the written string or false on failure.

Changes to the fputcsv Function

PHP 8.4

PHP 8.1

  • Optional parameter added - #6: string $eol = "\n"
 fputcsv(
     $stream,
     array $fields,
     string $separator = ",",
     string $enclosure = "\"",
-    string $escape = "\\"
+    string $escape = "\\",
+    string $eol = "\n"
   ): int|false

PHP 8.0

  • Return type added: int|false
  • Parameter name of parameter #1 changed: $fp to $stream
  • Parameter type added for parameter #2 ($fields): array
  • Parameter name of parameter #3 changed: $delimiter to $separator
  • Parameter type added for parameter #3 ($separator): string
  • Parameter default value added for position #3 ($separator): ","
  • Parameter type added for parameter #4 ($enclosure): string
  • Parameter default value added for position #4 ($enclosure): "\""
  • Parameter name of parameter #5 changed: $escape_char to $escape
  • Parameter type added for parameter #5 ($escape): string
  • Parameter default value added for position #5 ($escape): "\\"
  fputcsv(
-     $fp,
+     $stream,
-     $fields,
+     array $fields,
-     $delimiter,
+     string $separator = ",",
-     $enclosure,
+     string $enclosure = "\"",
-     $escape_char
+     string $escape = "\\"
-   )
+   ): int|false

PHP 7.0

  • Optional parameter added - #5: $escape_char
 fputcsv(
     $fp,
     $fields,
     $delimiter,
-    $enclosure
+    $enclosure,
+    $escape_char
   )

fputcsv Function Availability

PHP VersionAvailability
PHP 8.5Future Release Yes
PHP 8.4Upcoming Release Yes
PHP 8.3Supported (Latest) Yes
PHP 8.2Supported Yes
PHP 8.1Security-Fixes Only Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes