<?php
php
$file = 'test.csv';
$file = file($file);
$encapsulator = '';
$delimiter = '';
if(is_array($file))
{
$lastLine = trim($file[count($file)-1]);
$encapsulator = substr($lastLine, -1, 1);
echo "Encapsulator is {$encapsulator}<br />";
$delimPos = strrpos(substr($lastLine, 0, strlen($lastLine)-1), $encapsulator);
$delimiter = substr($lastLine, $delimPos-1, 1);
echo "Delimiter is {$delimiter}";
}
else
{
echo 'Error<br />';
print_r($file);
}
?>
To summarize, it reads the last line of the csv and strips whitespace from the beginning and end. Then assumes the last character to be an encapsulator.
Using the encapsulator, it scans backwards for the next encapsulator (the start of the last field), and uses the character before that as the delimiter.
Obviously, if there is only one column on the last line you wont get teh delimiter because you'll be at the start of the line, so you'd need to check for that and scan the next line up.
The reason you have to start from the end of the file is because you can't guaruntee the encapsulators will be present at the start of the file, but they are always present at the end.
Anyway, I'm pretty sure that should work for what you need, as long as you can translate it in to whatever language you use and add appropriate checks.