W3C home > Mailing lists > Public > public-lod@w3.org > January 2010

PHP RDF fetching code

From: Hugh Glaser <hg@ecs.soton.ac.uk>
Date: Mon, 25 Jan 2010 18:10:18 +0000
To: "public-lod@w3.org" <public-lod@w3.org>
Message-ID: <EMEW3|fa3f1f4587cc8071450e97e303a129d6m0OIAN02hg|ecs.soton.ac.uk|C7838F0A.FB2C%hg@ecs.soton.ac.uk>
OK, hereís some fun for you...
(Excuse me if it has been discussed before, and just point me at it :-) )

Having struggled through the php manual for cURL, I have come up with the following draft for getting an RDF document, given a URI.

                        $ch = curl_init();
                        curl_setopt($ch, CURLOPT_URL, $_REQUEST['uri']);
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
                        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/rdf+xml, text/n3, text/rdf+n3, text/turtle, application/x-turtle, application/turtle, text/plain"));
                        $data = curl_exec($ch);
                        $info = curl_getinfo($ch);

                        if ($data === FALSE || $info['http_code'] != 200) {

What does anyone think?
Iím sure there are a bunch of improvements/corrections.

As a (hopefully) separate issue, the MIME types will probably generate some discussion, but it is the PHP I am primarily asking about at the moment.

Received on Monday, 25 January 2010 18:10:53 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:20:55 UTC