0

I am working on a genealogy project and I am trying to read the GEDCOM (*.ged) file format.

Instead of using columns, they choose to use lines and on each line has a root node and following sub node with its affiliated values, and their associated (child) nodes. Very simple numbering system 0 (root) node and 1,2,3... another root node and so on.

The problem that I'm having is that I have placed variables as (check points) indicating what part/section the program would be in, head / submission / individual, in order to minimize just what part of the program it is in, at what point. But one of the child nodes (particularly DATE) is inside the indi-birt-date as well as indi-chan-date, and there for passes / fails to differentiate and parse the correct date in intended check point.

Unlike head and submission, there are multiple (indi)viduals. And there for its difficult to create the right code to match the scenario.

preg_match('/^\d.(DATE)\s(.*)/i', '2 DATE Jan 01 2022', $matches); is the same condition for both instances. And therefor my birthdate is overridden with the final update (chan-date)

What I would like to know is how do I create a depth scenario, as a variable, and decide just what level I am in the program, and there for limit just what matches and executing code limits to the depth the program is at.

Update: I moved a couple of checkpoints inside so they could only be opened once per individual, and closed when they are not needed.

sample code

Barry Dick
  • 161
  • 3
  • 16
  • Hi! Not answering directly but did you have a look at these kind of libraries: https://github.com/mrkrstphr/php-gedcom ? – claire_ Jul 30 '22 at 20:38

1 Answers1

0

I have created a image showing how to create/read from GED file in PHP.

The code assumes that it has a file open (fopen) and reading line by line (while-fgets-loop). Instead of reading the entire file into memory (arrays), its best to store it all into a relational database. That code can be written in place of the first die() function. Also its best to mention that the programs that create these GED files, also have hidden characters in front of the line as a space (zero width no-break space Unicode code point).

So use the following $line = preg_replace('/[\x{200B}-\x{200D}\x{FEFF}]/u', '', trim($line));

sample / demo codeenter image description here

Barry Dick
  • 161
  • 3
  • 16