Given an absolute path to a CSV or any text file and a list of possible delimiters and assuming lines are up to 4096 characters long, I use
<?php
function guess_delimiter($file, $delimiters=[',',';'])
{
$h = fopen($file,'r');
$count = [];
foreach ($delimiters as $del) {
$count[$del] = 0;
while (($bufer = fgets($h, 4096)) !== false) {
$count[$del]+=substr_count($bufer, $del);
}
rewind($h);
}
fclose($h);
return array_search(max($count), $count);
}