How to retrieve & use the JSON response of website in PHP?
I have to access the following url in my PHP code .
https://test.httpapi.com/api/domains/available.json?auth-userid=0&auth-password=password&domain-name=domain&tlds=com&tlds=info&tlds=org&tlds=net&suggest-alternative=true
the above url returns a json response. My query is " how to retrieve the开发者_运维问答 response in php code ".
Please provide a code sample for this as i'm quite new in this area of php !
Use PHP JSON junctions json_decode and json_encode http://php.net/manual/en/function.json-encode.php
$json = file_get_contents("https://test.httpapi.com/api/domains/available.json?auth-userid=0&auth-password=password&domain-name=domain&tlds=com&tlds=info&tlds=org&tlds=net&suggest-alternative=true");
$myArr = json_decode($json);
var_dump($myArr);
$json = file_get_contents("https://test.httpapi.com/api/domains/available.json?auth-userid=0&auth-password=password&domain-name=domain&tlds=com&tlds=info&tlds=org&tlds=net&suggest-alternative=true");
$response = json_decode( stripslashes($json) );
should work quite well
精彩评论