fork download
  1. <?php
  2.  
  3. $json_string = '{
  4. "access_token": "ab5f49438xfbc2df2a6a927a02b5c2e2442am982c71ee8re4aee1b2c64783ddc7cab4050ed05d6aa",
  5. "token_type": "Bearer",
  6. "expires_in": 300,
  7. "refresh_token": "ab4156db100f148b6cgd7e17097e1f1c25dcf32a53ec64w287c0bcc5b8f8aa2d0799a413567b8d73",
  8. "scope": "user_account send_currency currency_exchange"
  9. }';
  10.  
  11. $json_parse = json_decode($json_string);
  12.  
  13. echo "<pre>";
  14. echo "access_token :" . $json_parse->access_token . PHP_EOL;
  15. echo "token_type :" . $json_parse->token_type . PHP_EOL;
  16. echo "expires_in :" . $json_parse->expires_in . PHP_EOL;
  17. echo "refresh_token :" . $json_parse->refresh_token . PHP_EOL;
  18. echo "scope :" . $json_parse->scope . PHP_EOL;
  19. echo "</pre>";
  20.  
  21. // Transforma o escopo das variáveis acessíveis externamente
  22. // O item deve ser um array, como o json_decode transforma em objeto
  23. // precisamos transformar em array
  24. extract((array) $json_parse);
  25.  
  26. echo "<pre>";
  27. echo "access_token :" . $access_token . PHP_EOL;
  28. echo "token_type :" . $token_type . PHP_EOL;
  29. echo "expires_in :" . $expires_in . PHP_EOL;
  30. echo "refresh_token :" . $refresh_token . PHP_EOL;
  31. echo "scope :" . $scope . PHP_EOL;
  32. echo "</pre>";
  33.  
  34.  
Success #stdin #stdout 0s 82880KB
stdin
Standard input is empty
stdout
<pre>access_token  :ab5f49438xfbc2df2a6a927a02b5c2e2442am982c71ee8re4aee1b2c64783ddc7cab4050ed05d6aa
token_type    :Bearer
expires_in    :300
refresh_token :ab4156db100f148b6cgd7e17097e1f1c25dcf32a53ec64w287c0bcc5b8f8aa2d0799a413567b8d73
scope         :user_account send_currency currency_exchange
</pre><pre>access_token  :ab5f49438xfbc2df2a6a927a02b5c2e2442am982c71ee8re4aee1b2c64783ddc7cab4050ed05d6aa
token_type    :Bearer
expires_in    :300
refresh_token :ab4156db100f148b6cgd7e17097e1f1c25dcf32a53ec64w287c0bcc5b8f8aa2d0799a413567b8d73
scope         :user_account send_currency currency_exchange
</pre>