2

i have the following route:

Route::get('/verifica-dominio', function() {
$dom = Input::get('dominio');
$dominio = explode('.', Input::get('dominio'));
$name= $dominio[0];
$tld = $dominio[1];
$url =  'https://api.cloudns.net/domains/check-available.json?auth-id=1243&auth-password=KNK-dn5.&name=' . $name . '&tld[]=' . $tld;
$json = file_get_contents($url, true, stream_context_create(['socket' => ['bindto' => '0:0']]));
$j = json_decode($json);
return var_dump($j);

});

it return this object

object(stdClass)#1023 (1) { ["provola.com"]=> object(stdClass)#1024 (1) { ["status"]=> int(0) } }

how i can got status=1 in my code?

5
  • you shouldn't return var_dump ... code it how your supposed! Commented Jul 21, 2017 at 14:01
  • Try this $array = get_object_vars($j); var_dump(array); and see what youget !! Commented Jul 21, 2017 at 14:06
  • of course json offer this response {"provola.com":{"status":0}} but if i try to extract 0 from status got ILLEGAL STRING error Commented Jul 21, 2017 at 14:06
  • @Maraboc return this array(1) { ["provola.com"]=> object(stdClass)#1024 (1) { ["status"]=> int(0) } } Commented Jul 21, 2017 at 14:09
  • Then you can access status like this : $array[$tld]->status ! Commented Jul 21, 2017 at 14:15

2 Answers 2

2

you can use json_decode() , its takes a JSON encoded string and converts it into a PHP variable.

$j = json_decode($json, TRUE);
print_r($j);

and your php section you can use php array to you can process data

this is common format

<?php
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
echo "<pre>";
print_r(json_decode($json, true));

?>

and this output is :

Array
(
    [a] => 1
    [b] => 2
    [c] => 3
    [d] => 4
    [e] => 5
)

for more information

http://php.net/manual/en/function.json-decode.php

Sign up to request clarification or add additional context in comments.

Comments

0

Pass TRUE as the second argument to json_decode() to make it decode the JSON to arrays and not to objects:

$j = json_decode($json, TRUE);
print_r($j);

Output:

Array
(
    [provola.com] => Array
        (
            [status] => 0
        )
)

Now everything became much clearer and easier to handle. $j['pravola.com']['status'] is the value you are looking for.

If it is not more clear then read about PHP arrays and insist on the "Accessing array elements with square bracket syntax" section.

I guess the key 'pravola.com' is what you pass to the remote API in argument tld. If this is the case then you can use $j[$tld]['status'] to get the data you need.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.