trim($original), 'translation' => trim($translation), 'notes' => [] ]; } } else { // 没有等号的行 if ($currentRecord !== null && empty($currentRecord['translation'])) { // 情况1: 上一行只有巴利文(等号后为空),当前行是缅文翻译 $currentRecord['translation'] = trim($line); } elseif ($currentRecord === null) { // 情况2: 第一行没有等号,可能是不完整的巴利文 $currentRecord = [ 'original' => trim($line), 'translation' => '', 'notes' => [] ]; } else { // 其他情况视为注释内容 $pendingNotes[] = trim($line); } } } // 保存最后一条记录 if ($currentRecord !== null) { $currentRecord['notes'] = $pendingNotes; $records[] = $currentRecord; } return $records; } /** * 解析文件 * * @param string $filePath * @return array */ public function parseFile(string $filePath): array { if (!file_exists($filePath)) { throw new \InvalidArgumentException("文件不存在: {$filePath}"); } $content = file_get_contents($filePath); return $this->parse($content); } }