ARC SPARQL Endpoint - Get results in json - php

can anyone help me to figure out how to get query results back in json or xml etc when using the Arc sparql endpoint?
I am using the following code to get the result of my query:
$endPoint->handleQueryRequest($query);
$result = $endPoint->getResult();
I have looked through the code and tried passing some paramaters - trial and error - but can not get anywhere.

Its ok, i have figured it out - I was using an endpoint when I should have just been using a store.
It would still be interesting to see how you can query the endpoint directly through a php class - i.e. not through a get or post request - and specify what format the results should be in.

I had a exactly same problems, but with Java. I wanted to use the JSon and also to use the timeout from dbpedia, but Jena (as far as I know) had no solution for this...
Well in the end I didn't use any SPARQL library, and just requested to the whole address (http://dbpedia.org/sparql?default-graph-uri=GRAPH&query=QUERY&...&timeout=TIMEOUT&format=FORMAT), and it works (of course)

Related

get web page content using php script and save it in my db

I want to get the content of this 1st and 2nd webpage https://www.goodreads.com/search?utf8=%E2%9C%93&q=%D8%B3%D9%8A%D8%A7%D8%B3%D8%A9&search_type=books
and then store it in my database and then make the list is searchable.so after I googled I found that I can do it like this
$url = "https://www.goodreads.com/search?utf8=%E2%9C%93&q=%D8%B3%D9%8A%D8%A7%D8%B3%D8%A9&search_type=books";
function get_links($url){
$input = file_get_contents($url);
echo $input;
}
get_links($url);
my problem is how can I get the 2nd page content also and how can I store these books in my database to the list searchable
The answer is not that easy...
Options
Getting the pages (Not recommended)
To get a later page you can send the "page argument" in your request:
e.g.:
https://www.goodreads.com/search?page=2&q=%D8%B3%D9%8A%D8%A7%D8%B3%D8%A9&search_type=books&tab=books&utf8=%E2%9C%93
But to get the Elements into a nice structure you need to parse the HTML you get which is realy hard.
Use the API (recommended)
At https://www.goodreads.com/api/index you can find the documentation for goodreads API which returns example as response and is easily parseable.
Parse XML in PHP
If you use the API you can parse the XML-response with SimpleXML.
See example 1 & 2: http://php.net/manual/en/simplexml.examples-basic.php
Saving to database
If you are a beginner you might read some tutorials about how to use mysql with php and PDO. But you may also have a look at RedBeanPHP which is an really easy to use ORM for databases.
For getting 2nd page you will have to append on the url ?page=2
In case that you need to get other pages, you can use a for loop if you don't know how to use for loop, please google php for loop
For the database, google php mysql insert

URL object json NAGIOS

I have a question, I work with many monitoring web, if you know PRTG you can make a URL that returns the status of the various sensors and alarm messages, and process this information in different web graphic pages; Now I have been asked to do the same but with the tool Will they hear the NAGIOS process? I do not understand how it should build the URL if alguin worked with this I would appreciate help me.
Example URL with PRTG:
https://10.213.8.25/api/table.json?content=sensors&output=json&columns=status,message&filter_status=4&filter_objid=9336&filter_objid=9495&filter_objid=9496
Return:
{"prtg-version":":","treesize":000,"sensors":[{"objid":1001.....}]}
You can get JSON starting with Nagios Core version 4.0.7.
Just browse to http://<address_of_your_nagios_server>/nagios/jsonquery.html
and you'll find a JSON Query Generator page that can help your build your query URL, execute it, and get JSON results. After executing the query, on the right-hand side of the page, the generated URL will be given and below it, the results of the query. You can paste the generated URL into a browser or call from your application to get raw JSON.
More information on this feature can be found here: https://labs.nagios.com/2014/06/19/exploring-the-new-json-cgis-in-nagios-core-4-0-7-part-1/

Load the r_object of a GET request into a variable

I have searched extensively for this answer. Maybe it's just too simple to be posted. Please forgive me I am missing something really obvious. I am trying to use a piece of data (number value) from a GET request (I think it is the r_object value) that I access via a URL with an API key.
I am using an external service (called "teleduino") to read data (moisture/voltage readings) from a microprocessor unit (Arduino Uno with Ethernet shield). I use my personal API key from teleduino and the teleduino service uses php GET requests (in a JSON format I think). I can load the results into an iframe on my web page using javascript, but I need to use a real variable of the data not just view it in an iframe.
For example, if I load "http://us01.proxy.teleduino.org/api/1.0/328.php?k={my-key-here}&r=getAnalogInput&pin=16" into an iframe I get something like this (when the device is online) :
{status":200,"message":"OK","response":{"result:1,"time":0.22702789306641,"values":[877]}}
The number in the square brackets is the value I need to extract as a simple variable so I can display it on the page (instead of using iframes) and also use it in mathematical calculations and other functions.
That value I need (in the square brackets after "values") is I think the "r _object" in the $GET request because when I observe the URL : r=getAnalogInput&pin=16 is the crucial data I need. (It is the number of a voltage given on pin16 of that microprocessor, which refers to the soil moisture of that plant).
I have searched extensively but cannot find out how to load that value from the get request into a variable so I can use it in the javascript on my page.
I assume it is some simple php like
moisture = $_GET[URL,"values"] ....etc etc
I am assuming it is the php r_object. And I assume I need to use php or ajax as the data is coming from an outside server (the teleduino service), so pure javascript will not work.
I am happy to write some php onto the php file of my webpage, but I do not know what that php should be.
ANY ideas would be greatly appreciated - thank you so much!!!
$_GET is for getting parameters that were passed as parameters to your PHP script, not results from a remote API. I think this is what you want:
$results = file_get_contents($url);
$data = json_decode($results, true);
$moisture = $data['response']['values'][0];

PHP - filtering and passing data into my app

I am very new to programming and need a little help with getting data from a website and passing it into my PHP script.
The website is http://www.birthdatabase.com/.
I would like to plug in a name (First and Last) and retrieve the result. I know you can query the site by passing the name in the URL, but I am having problems scraping the results.
http://www.birthdatabase.com/cgi-bin/query.pl?textfield=FIRST&textfield2=LAST&age=&affid=
I am using the file_get_contents($URL) function to get the page but need help after that. Specifically, I would like to scrape only the results from a certain state if there are multiple results for that name.
Thanks for your help.
Read about POST method and its array ($_POST) ---> reference.
Similarly, there is GET method as well.
Why dont you see POST AND GET method?

PHP - curl or simplexml_load_file?

I'm trying to parse information from fonefinder.net. I was trying to use simplexmlload_file, but couldn't get the page to load successfully.
Now, I'm looking into Curl. But I'm not sure if this will work either.
I basically just want to take the html from the fonefinder page, and parse it to get phone carrier and city.
Is that possible? How?
SimpleXML will only work if the HTML is formatted correctly - and that is rarely the case ;)
You could do a simple cURL call to fetch the data and the easiest thing would probably be using a regular expression to get the information you need.
The solution however is not easy to supply you with, with nothing to go on. But this was an idea.
I Recommend using:
http://www.de.php.net/manual/en/function.file-get-contents.php to get the document
http://www.php.net/manual/en/domdocument.loadhtml.php to load it
http://www.php.net/manual/en/class.domxpath.php to get the information from it
Or use the search function here, that question must have been asked over and over, for example PHP: Fetch content from a html page using xpath()

Categories