52 lines
No EOL
1.7 KiB
PHP
52 lines
No EOL
1.7 KiB
PHP
<?php
|
|
$path = 'd:/Docker/jasan/ex/한경협 자산관리/한경협 직원 일람 2e9d19d26c9f414cb65e38320a21f912_all.csv';
|
|
$content = file_get_contents($path);
|
|
if (!mb_check_encoding($content, 'UTF-8')) {
|
|
$content = mb_convert_encoding($content, 'UTF-8', 'EUC-KR');
|
|
}
|
|
$lines = explode("\n", str_replace("\r", "", $content));
|
|
$headerLine = array_shift($lines);
|
|
$header = str_getcsv($headerLine);
|
|
|
|
$data = [];
|
|
$hierarchy = [];
|
|
|
|
foreach ($lines as $line) {
|
|
if (trim($line) === '')
|
|
continue;
|
|
$row = str_getcsv($line);
|
|
if (count($row) >= 17) { // ensure enough columns
|
|
$combined = array_combine($header, array_slice($row, 0, count($header)));
|
|
$company = trim($combined['회사'] ?? '');
|
|
$parent = trim($combined['상위 항목'] ?? '');
|
|
$dept = trim($combined['부서'] ?? '');
|
|
|
|
// Clean parent name (remove (...) part)
|
|
$parentClean = preg_replace('/\s*\(.*?\)$/', '', $parent);
|
|
|
|
if ($company) {
|
|
if (!isset($hierarchy[$company]))
|
|
$hierarchy[$company] = [];
|
|
if ($parentClean) {
|
|
if (!isset($hierarchy[$company][$parentClean]))
|
|
$hierarchy[$company][$parentClean] = [];
|
|
if ($dept && $dept !== $parentClean) {
|
|
$hierarchy[$company][$parentClean][] = $dept;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach ($hierarchy as $company => $parents) {
|
|
echo "🏢 " . $company . "\n";
|
|
foreach ($parents as $parent => $depts) {
|
|
echo " 📂 " . $parent . "\n";
|
|
$uniqueDepts = array_unique($depts);
|
|
foreach ($uniqueDepts as $d) {
|
|
echo " 📄 " . $d . "\n";
|
|
}
|
|
}
|
|
echo "\n";
|
|
}
|
|
?>
|