Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

79 lines (73 sloc) 2.4 KB
* Form to submit and display SPARQL queries
* This example presents a form that you can enter the URI
* of a a SPARQL endpoint and a SPARQL query into. The
* results are displayed using a call to dump() on what will be
* either a EasyRdf\Sparql\Result or EasyRdf\Graph object.
* A list of registered namespaces is displayed above the query
* box - any of these namespaces can be used in the query and PREFIX
* statements will automatically be added to the start of the query
* string.
* @package EasyRdf
* @copyright Copyright (c) 2009-2013 Nicholas J Humfrey
* @license
require_once realpath(__DIR__.'/..')."/vendor/autoload.php";
require_once __DIR__."/html_tag_helpers.php";
// Stupid PHP :(
if (get_magic_quotes_gpc() and isset($_REQUEST['query'])) {
$_REQUEST['query'] = stripslashes($_REQUEST['query']);
<title>EasyRdf SPARQL Query Form</title>
<style type="text/css">
.error {
width: 35em;
border: 2px red solid;
padding: 1em;
margin: 0.5em;
background-color: #E6E6E6;
<h1>EasyRdf SPARQL Query Form</h1>
<div style="margin: 0.5em">
print form_tag();
print label_tag('endpoint');
print text_field_tag('endpoint', "", array('size'=>80)).'<br />';
print "<code>";
foreach(\EasyRdf\RdfNamespace::namespaces() as $prefix => $uri) {
print "PREFIX $prefix: &lt;".htmlspecialchars($uri)."&gt;<br />\n";
print "</code>";
print text_area_tag('query', "SELECT * WHERE {\n ?s ?p ?o\n}\nLIMIT 10", array('rows' => 10, 'cols' => 80)).'<br />';
print check_box_tag('text') . label_tag('text', 'Plain text results').'<br />';
print reset_tag() . submit_tag();
print form_end_tag();
if (isset($_REQUEST['endpoint']) and isset($_REQUEST['query'])) {
$sparql = new \EasyRdf\Sparql\Client($_REQUEST['endpoint']);
try {
$results = $sparql->query($_REQUEST['query']);
if (isset($_REQUEST['text'])) {
print "<pre>".htmlspecialchars($results->dump('text'))."</pre>";
} else {
print $results->dump('html');
} catch (Exception $e) {
print "<div class='error'>".$e->getMessage()."</div>\n";
Jump to Line
Something went wrong with that request. Please try again.