Sparql request with CURL


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public function executeGetLocation(sfWebRequest $request)
  2. {
  3. $ressource = $request->getParameter('ressource');
  4. if(!empty($ressource))
  5. {
  6. $query = "SELECT ?location WHERE {{ <"
  7. . $ressource
  8. . "> <http://dbpedia.org/ontology/locationCity> ?location }}";
  9.  
  10. $searchUrl = 'http://dbpedia.org/sparql?'
  11. . 'query='.urlencode($query)
  12. . '&format=json';
  13.  
  14. if (!function_exists('curl_init')){
  15. die('CURL is not installed!');
  16. }
  17.  
  18. $ch= curl_init();
  19. curl_setopt($ch, CURLOPT_URL, $searchUrl);
  20. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  21. $response = curl_exec($ch);
  22. curl_close($ch);
  23.  
  24. return $this->renderText( json_encode($response));
  25. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.