-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_duplicates.php
More file actions
65 lines (56 loc) · 1.56 KB
/
check_duplicates.php
File metadata and controls
65 lines (56 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* check_duplicates.php
* Reads output.csv and lists duplicate 'نامک' entries along with their شناسه.
*/
ini_set('display_errors', 1);
error_reporting(E_ALL);
$outputCsv = __DIR__ . '/output.csv';
// ====== FUNCTIONS ======
function readCsv($filePath)
{
$rows = [];
if (!file_exists($filePath)) {
die("Error: File not found: $filePath\n");
}
if (($handle = fopen($filePath, 'r')) !== false) {
$headers = fgetcsv($handle);
if (!$headers) {
die("Error: CSV file has no headers.\n");
}
while (($data = fgetcsv($handle)) !== false) {
$rows[] = array_combine($headers, $data);
}
fclose($handle);
}
return [$headers, $rows];
}
// ====== MAIN SCRIPT ======
list($headers, $rows) = readCsv($outputCsv);
if (empty($rows)) {
die("Error: CSV file is empty.\n");
}
$idColumn = $headers[0];
$slugColumn = 'نامک';
if (!in_array($slugColumn, $headers)) {
die("Error: Column 'نامک' not found in CSV headers.\n");
}
$slugMap = [];
foreach ($rows as $row) {
$slug = $row[$slugColumn] ?? '';
$id = $row[$idColumn] ?? '';
if ($slug !== '') {
$slugMap[$slug][] = $id;
}
}
$duplicatesFound = false;
foreach ($slugMap as $slug => $ids) {
if (count($ids) > 1) {
$duplicatesFound = true;
echo "نامک: $slug\n";
echo "شناسه: " . implode(', ', $ids) . "\n\n";
}
}
if (!$duplicatesFound) {
echo "✅ No duplicate 'نامک' entries found.\n";
}