Answers for "get json data from api in php"

PHP
2

fetch value from json link in php

$ch = curl_init();
// IMPORTANT: the below line is a security risk, read https://paragonie.com/blog/2017/10/certainty-automated-cacert-pem-management-for-php-software
// in most cases, you should set it to true
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'url_here');
$result = curl_exec($ch);
curl_close($ch);

$obj = json_decode($result);
echo $obj->access_token;
Posted by: Guest on June-17-2020
1

web api return json example in php

$option = $_GET['option'];

if ( $option == 1 ) {
    $data = [ 'a', 'b', 'c' ];
    // will encode to JSON array: ["a","b","c"]
    // accessed as example in JavaScript like: result[1] (returns "b")
} else {
    $data = [ 'name' => 'God', 'age' => -1 ];
    // will encode to JSON object: {"name":"God","age":-1}  
    // accessed as example in JavaScript like: result.name or result['name'] (returns "God")
}

header('Content-type: application/json');
echo json_encode( $data );
Posted by: Guest on November-03-2020
0

php create json as request for call another api

$upgradeFlutterButton = new FlutterButton("UPGRADE", "2", "com.COMPANY.APP_NAME");

        $postData = array(
            'app_id' => 1,
            'actions' => [
              $upgradeFlutterButton
            ],
            'user_id' => 2,
        );

        $objectRequest = new \Illuminate\Http\Request();
        $objectRequest->setMethod('POST');
        $objectRequest->request->add($postData);

        return $objectRequest;
Posted by: Guest on June-28-2021

Code answers related to "get json data from api in php"

Browse Popular Code Answers by Language