PHP | fputcsv( ) Function (original) (raw)

Last Updated : 13 Jun, 2018

The fputcsv() function in PHP is an inbuilt function which is used to format a line as CSV(comma separated values) file and writes it to an open file. The file which has to be read and the fields are sent as parameters to the fputcsv() function and it returns the length of the written string on success or FALSE on failure.Syntax:

int fputcsv ( file,file, file,fields, separator,separator, separator,enclosure )

Parameters: The fputcsv() function in PHP accepts four parameters as explained below.

Return Value: This function returns the length of the written string on success or FALSE on failure.Exceptions:

Below programs illustrate the fputcsv() function:Program 1:

php `

`

Output:

Raj, Singh, Developer, Mumbai Sameer, Pandey, Tester, Bangalore Raghav, Chauhan, Manager, Delhi

Program 2:

php `

`

Output:

abc, efg, jhi, klm 123, 456, 789 11aa, 22bb, 33cc, 44dd

Reference: http://php.net/manual/en/function.fputcsv.php