How can you determine the character encoding of a CSV file in PHP?

When working with CSV files in PHP, it's important to determine the character encoding to properly handle special characters. One way to determine the character encoding of a CSV file is by using the `mb_detect_encoding()` function in PHP. This function detects the encoding of a string by checking for specific byte sequences that are unique to different encodings.

// Open the CSV file
$handle = fopen('file.csv', 'r');

// Read the first line of the file
$firstLine = fgets($handle);

// Determine the character encoding of the first line
$encoding = mb_detect_encoding($firstLine, 'UTF-8, ISO-8859-1, Windows-1252');

// Output the detected encoding
echo 'Character Encoding: ' . $encoding;

// Close the file
fclose($handle);