liberu-genealogy / php-gedcom
A GEDCOM file parser (read + write) for PHP 8.0+
Fund package maintenance!
liberu-genealogy
Installs: 1 599
Dependents: 2
Suggesters: 0
Security: 0
Stars: 75
Watchers: 4
Forks: 40
Open Issues: 0
Requires
- php: >=8.3
Requires (Dev)
- driftingly/rector-laravel: ^0.25.0
- phpunit/phpunit: 11.*
- rector/rector: *
- squizlabs/php_codesniffer: 3.6.*
- dev-main
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.4.10
- v1.4.9
- v1.4.8
- v1.4.7
- v1.4.6
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4
- v1.3.17
- v1.3.16
- v1.3.15
- v1.3.14
- v1.3.13
- v1.3.12
- v1.3.11
- v1.3.10
- v1.3.9
- v1.3.8
- v1.3.7
- v1.3.6
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-sweep/psr4_ecc88
- dev-sweep/add_status_badge_to_readmemd_for_runtest
- dev-sweep/create_github_workflow_to_run_phpunit_us
- dev-sweep/docstrings-addition_1a773
- dev-sweep/unit-tests-dataoptimizer-sour
- dev-sweep/fix-typo-in-function-name
- dev-sweep/unit-tests-for-new-logic
- dev-sweep/docstrings-enhancement
- dev-sweep/improve_codebase_for_modularization_and
- dev-sweep/add-docstrings-to-writer-test
- dev-sweep/add-unit-tests-writer-test
- dev-sweep/add-docstrings-to-writer
- dev-sweep/refactor-convert-method
- dev-sweep/add-unit-tests_62a15
- dev-sweep/docstrings-addition_ba099
- dev-sweep/add-docstrings
- dev-sweep/psr4
- dev-sweep/refactor-writer-test
- dev-sweep/write_full_tests
- dev-sweep/docstrings-addition
- dev-sweep/docstring-addition
- dev-sweep/convert-method
- dev-sweep/refactor-parser-tests
- dev-sweep/add-unit-tests
- dev-sweep/add-unit-tests-convert-method-writer
- dev-sweep/add-parser-tests
- dev-sweep/add-docstring-to-convert-function
- dev-sweep/refactor-writer-modularity
- dev-sweep/multiple_events_of_same_type
- dev-sweep/missing_data_element
- dev-sweep/your_example_does_not_work
- dev-sweep/revert-convert-method-changes
- dev-sweep/refactor_codebase_to_use_php_83
- dev-sweep/add-sweep-config
- dev-master
This package is auto-updated.
Last update: 2024-10-26 14:41:00 UTC
README
Requirements
- php-gedcom 1.0+ requires PHP 8.3 (or later).
Installation
There are two ways of installing php-gedcom.
Composer
To install php-gedcom in your project using composer, simply add the following require line to your project's composer.json
file:
{
"require": {
"liberu-genealogy/php-gedcom": "2.0.*"
}
}
Download and __autoload
If you are not using composer, you can download an archive of the source from GitHub and extract it into your project. You'll need to setup an autoloader for the files, unless you go through the painstaking process if requiring all the needed files one-by-one. Something like the following should suffice:
spl_autoload_register(function ($class) { $pathToGedcom = __DIR__ . '/library/'; // TODO FIXME if (!substr(ltrim($class, '\\'), 0, 7) == 'Gedcom\\') { return; } $class = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php'; if (file_exists($pathToGedcom . $class)) { require_once($pathToGedcom . $class); } });
Usage
To parse a GEDCOM file and load it into a collection of PHP Objects, simply instantiate a new Parser object and pass it the file name to parse. The resulting Gedcom object will contain all the information stored within the supplied GEDCOM file:
$parser = new \Gedcom\Parser(); $gedcom = $parser->parse('tmp.ged'); foreach ($gedcom->getIndi() as $individual) { $names = $individual->getName(); if (!empty($names)) { $name = reset($names); // Get the first name object from the array echo $individual->getId() . ': ' . $name->getSurn() . ', ' . $name->getGivn() . PHP_EOL; } }
Contributing
Pull requests are welcome, as are issues.
License
MIT License (see License.md). This means you must retain the copyright and permission notice is all copies, or substantial portions of this software.