What are the potential pitfalls of using fputcsv() in PHP for writing CSV files?

One potential pitfall of using fputcsv() in PHP for writing CSV files is that it does not handle encoding issues properly, which can result in corrupted characters in the CSV file. To solve this issue, you can specify the encoding when opening the file using fopen() and setting the encoding parameter to 'UTF-8'.

$fp = fopen('file.csv', 'w');
stream_filter_append($fp, 'convert.iconv.UTF-8/ISO-8859-1');
fputcsv($fp, $data);
fclose($fp);