forked from FamilySearch/gedcomx-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminimal_gedcom_parser.php
More file actions
42 lines (36 loc) · 1.1 KB
/
minimal_gedcom_parser.php
File metadata and controls
42 lines (36 loc) · 1.1 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
<?php
class MinimalGedcomParser {
private $file;
public function __construct($file) {
$this->file = $file;
}
public function parse() {
$contents = file_get_contents($this->file);
return $this->parseLines(explode("\n", $contents));
}
private function parseLines($lines) {
$data = [];
foreach ($lines as $line) {
$data[] = $this->parseLine($line);
}
return $data;
}
private function parseLine($line) {
$parts = explode(' ', $line, 3);
return [
'level' => isset($parts[0]) ? $parts[0] : null,
'tag' => isset($parts[1]) ? $parts[1] : null,
'value' => isset($parts[2]) ? $parts[2] : null
];
}
}
// Använd minimal parser för att läsa GEDCOM-fil
try {
$gedcomFile = 'D:/ASGR_System/Projekt_NextGen_1.03/GEDCOM/file.ged';
$parser = new MinimalGedcomParser($gedcomFile);
$gedcomData = $parser->parse();
echo 'GEDCOM Innehåll: ' . print_r($gedcomData, true) . PHP_EOL;
} catch (Exception $e) {
echo 'Fel: ' . $e->getMessage() . PHP_EOL;
}
?>