EasyRdf is a PHP library designed to make it easy to consume and produce RDF.
This is a fork of EasyRdf which I maintain in my spare time. My objective is to keep EasyRdf alive and usable on latest PHP versions. Code is more or less maintained but not developement any further. If you wanna participate, feel free to open a pull request! For more information about this fork, scroll at the end of this document.
EasyRdf is a PHP library designed to make it easy to consume and produce RDF. It was designed for use in mixed teams of experienced and inexperienced RDF developers. It is written in Object Oriented PHP and has been tested extensively using PHPUnit.
After parsing EasyRdf builds up a graph of PHP objects that can then be walked around to get the data to be placed on the page. Dump methods are available to inspect what data is available during development.
Data is typically loaded into an
EasyRdf\Graph object from source RDF
documents, loaded from the web via HTTP. The
simplifies loading and saving data to a SPARQL 1.1 Graph Store.
SPARQL queries can be made over HTTP to a Triplestore using the
ASK queries will return an
EasyRdf\Sparql\Result object and
DESCRIBE queries will return
$foaf = new \EasyRdf\Graph("http://njh.me/foaf.rdf"); $foaf->load(); $me = $foaf->primaryTopic(); echo "My name is: ".$me->get('foaf:name')."\n";
- PHP 7.1 or higher
- PHP Extensions: dom, mbstring, pcre, xmlreader
- PHP Libs: libxml
- No required external dependencies upon other libraries (PEAR, Zend, etc...)
- Library runs in Linux and Windows environments
- Extensive unit tests written using PHPUnit
- Built-in parsers and serialisers: RDF/JSON, N-Triples, RDF/XML, Turtle
- Optional parsing support for: ARC2, rapper
- Optional support for
- Type mapper - resources of type
foaf:Personcan be mapped into PHP object of class
- Support for visualisation of graphs using GraphViz
- Comes with a number of examples
basic.php- Basic "Hello World" type example
basic_sparql.php- Example of making a SPARQL
converter.php- Convert RDF from one format to another
dump.php- Display the contents of a graph
foafinfo.php- Display the basic information in a FOAF document
foafmaker.php- Construct a FOAF document with a choice of serialisations
graph_direct.php- Example of using
graphstore.php- Store and retrieve data from a SPARQL 1.1 Graph Store
graphviz.php- GraphViz rendering example
html_tag_helpers.php- Rails Style html tag helpers to make the EasyRdf examples simpler
httpget.php- No RDF, just test
open_graph_protocol.php- Extract Open Graph Protocol metadata from a webpage
serialise.php- Basic serialisation example
sparql_queryform.php- Form to submit SPARQL queries and display the result
uk_postcode.php- Example of resolving UK postcodes using uk-postcodes.com
wikidata_villages.php- Fetch and information about villages in Fife from Wikidata
zend_framework.php- Example of using
Contributions are welcome! Please read CONTRIBUTING.md for further information.
For further information about extending / hack EasyRdf please read DEVELOPER.md.
Further mainainers are possible, please send an email to @k00ni.
The easiest way of trying out some of the examples is to use the PHP command to run a local web server on your computer.
php -S localhost:8080 -t examples
Then open the following URL in your browser: http://localhost:8080/
EasyRdf was in maintenance mode since 2017 (link) and not actively maintained since. There were 6+ pull requests pending at that time with fixes and new features. Its sad to see another RDF PHP project die slowly, so I decided to clean house and give the code a new home (further info). A few months in late 2020 EasyRdf was actively improved (me being a co-maintainer for a while), but that stopped and decay began again. It was a frustating time, lets leave it at that.
In the end I decided to abandon my old fork and start fresh with latest EasyRdf improvements in this repository.
This fork (v1.*) aims to be a drop-in replacement for the
easyrdf/easyrdf package, which means, you can use it without changing your code. But you should still read the notes of the latest release, to make sure nothing unexpected happens after an update.
This repository is set up in a way to lower the maintenance overhead in comparison to the original version. Test related tool was partly replaced with more lightweight solutions. Furthermore this repository is held by an organization instead of a user, which allows more flexible maintenance.
As stated above, main objective is to keep EasyRdf's legecay code up to date and compatible with latest PHP versions. I welcome pull requests and try to react as fast as possible. If there are useful pull requests in easyrdf/easyrdf (and I have time to spare), I will picked them up and integrate them here (for instance #9, #14).