What potential pitfalls should be considered when using file() and fputcsv() functions in PHP for handling CSV files, especially when dealing with non-standard formatting?

When using file() and fputcsv() functions in PHP for handling CSV files with non-standard formatting, potential pitfalls include incorrect parsing of data due to delimiter or enclosure characters not being properly handled. To avoid this, it is important to set the correct delimiter and enclosure characters when using fputcsv() and to handle any special cases manually when reading the CSV file with file().

// Set the delimiter and enclosure characters
$delimiter = ';'; // Set the delimiter to semicolon
$enclosure = '"'; // Set the enclosure character to double quotes

// Read CSV file using file() and handle special cases
$lines = file('data.csv');
foreach ($lines as $line) {
    $data = str_getcsv($line, $delimiter, $enclosure);
    // Handle data processing here
}