user364620
user364620

Reputation: 21

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 !

Upvotes: 2

Views: 639

Answers (2)

helle
helle

Reputation: 11660

$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

Upvotes: 2

Lizard
Lizard

Reputation: 45022

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);

Upvotes: 3

Related Questions