Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
function findSeparator($content) {
$rows = explode("\n", $content);
$counts = array(
';' => 0,
',' => 0,
"\t" => 0
);
foreach ($rows as $row) {
if (strpos($row, ';') !== false) {
$counts[';']++;
}
if (strpos($row, ',') !== false) {
$counts[',']++;
}
if (strpos($row, "\t") !== false) {
$counts["\t"]++;
}
}
if ($counts[';'] > 0 && $counts[','] > 0) {
return false;
}
arsort($counts);
return key($counts);
}
$content = "Строка1,строка2;строка3
Строка1;строка2;строка3
Строка1,строка2,строка3";
$separator = findSeparator($content);
if ($separator === false) {
echo "Строки содержат и точку с запятой, и запятую";
} else {
echo "Наиболее часто используемый разделитель: $separator";
}