Definition:
The PHP fputcsv() function formats a line (passed as a fields array) as CSV and writes it (terminated by a newline) to the specified file stream.
fputcsv(file, fields, separator, enclosure, escape)
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 |
The example below Format a line as CSV and writes it to an open file :
Output :
EmpID,Name,Age,Salary
1,John,25,3000
2,Marry,24,2750
3,Jo,27,2800