Whilst a CSV file has format, the exact format of each line is unknown, and verifying if a file is in CSV format is almost impossible.
Both of the below formats are perfectly valid for an CSV parser, such as str_getscv.
Perhaps the best that can be hoped for, is defining what makes a file not a CSV file. Basically, if it does not match one of the MIME types that a CSV file could possibly be.
public function isCSV( $file )
$csv_mime_types = [
$finfo = finfo_open( FILEINFO_MIME_TYPE );
$mime_type = finfo_file( $finfo, $file );
return in_array( $mime_type, $csv_mime_types );
$file = "my_file.csv";
if( isCSV( $file )
echo "This is a CSV file";
echo "This is not a CSV file";