$json = file_get_contents('url_here');
$obj = json_decode($json);
echo $obj->access_token;

For this to work, file_get_contents requires that allow_url_fopen is enabled. This can be done at runtime by including:

ini_set("allow_url_fopen", 1);

You can also use curl to get the URL. To use curl, you can use the example found here:

$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(obj = json_decode($result);
echo $obj->access_token;
Answer from Prisoner on Stack Overflow
🌐
ReqBin
reqbin.com › req › php › 5nqtoxbx › get-json-example
PHP | How to get JSON from URL?
To request JSON from an URL using PHP, you need to send an HTTP GET request to the server and provide the Accept: application/json request header with your request. The Accept header tells the server that our PHP client is expecting JSON.
🌐
Koding Made Simple
kodingmadesimple.com › 2016 › 02 › get-json-from-url-in-php.html
Get JSON from URL in PHP
The php function file_get_contents($url) send a http request to the provided url and returns json data. The function json_decode($json) decodes the provided json string and returns as a PHP object.
🌐
Tania's Website
taniarascia.com › how to request json api data with javascript or php
How to Request JSON API Data with JavaScript or PHP | Tania Rascia's Website
$url = 'data.json'; // path to your JSON file $data = file_get_contents($url); // put the contents of the file into a variable $characters = json_decode($data); // decode the JSON feed
🌐
Edureka Community
edureka.co › home › community › categories › blockchain › extract data from json url result php
Extract data from Json url result php | Edureka Community
September 3, 2018 - I am trying to run a url for getting balance of a address. Which gives the JSON: { "balance": ... > But it returns nothing. What am I doing wrong?
🌐
Delft Stack
delftstack.com › home › howto › php › php get json from url
How to Get JSON Object From URL in PHP | Delft Stack
February 2, 2024 - Use the curl_close() function to close the $curl variable. Next, use the json_decode() function to change the JSON object to PHP object and display the title object. Thus, we can get the JSON object from a URL using curl.
🌐
Kirby Forum
forum.getkirby.com › the cms › questions
Get JSON data from external website and parse it to show in HTML - Questions - Kirby Forum
March 6, 2018 - Is there a simple example how to fetch JSON data from an external website (like for example http://openweathermap.org/current ) and parse one of the values (e.g. ‘temp’) so it would show up in my HTML? All i found so fa…
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-pass-json-data-in-a-url-using-curl-in-php
How to Pass JSON Data in a URL using CURL in PHP ? - GeeksforGeeks
July 23, 2025 - Put JSON data in a PHP array and set up JSON data. And using json_encode() encode it into JSON string. Setting the options for the cURL. Fetching $url using CURLOPT_URL. Switching request type from get to post using CURLOPT_POST.
🌐
ReqBin
reqbin.com › req › php › ewk2va7p › get-request-to-retrieve-a-json
PHP | How do I send a get JSON request?
To get JSON from the server using PHP, you must send an HTTP GET request and pass the "Accept: application/json" HTTP header, which will tell the server that the client expects JSON in response.
🌐
W3Schools
w3schools.com › js › js_json_php.asp
JSON PHP
On the client, make a JSON object that describes the numbers of rows you want to return. Before you send the request to the server, convert the JSON object into a string and send it as a parameter to the url of the PHP ...
Top answer
1 of 1
1

You already have the JSON .. No need for a loop .. Just drill down to the URL ..

<?php
    $content = file_get_contents("https://code.directadvert.ru/show.cgi?adp=5357330&json=22");
    $content = utf8_encode($content);
    $result = json_decode($content, true);

    $url = $result['news'][0]['target_url'];
    
    echo $url;

When you json_decode -- Your $result becomes:

Array
(
    [news] => Array
        (
            [0] => Array
                (
                    [id] => 10906072
                    [pubdate] => 1602148428
                    [site_name] => fashion2news.com
                    [img] => https://cdn.directadvert.ru/cdn/images/100x100/40/8154740.jpg
                    [target_url] => https://fashion2news.com/tops-tees/diana-gurckaja-pritvorjalas-slepoj-40-let/?utm_medium=MarketGid&utm_source=MarketGid&utm_campaign=MarketGid&utm_term={widget_id}&utm_content=3219275&MarketGid
                    [rating] => 3
                    [title] => Ëîæü è öèíèçì ãîäàìè: ñòðàíà ñìîëêëà, óçíàâ, êåì îêàçàëàñü Ãóðöêàÿ
                    [created] => 1602148428
                    [url] => https://code.directadvert.ru/click/?x=Z8162cWaXn9LS96s2B_LJkN-p8fHQJjfLQ_0_mz4prYJYHjAAs3ju0g8WZ7WYJ_XhxC6dJJXzv-ZQOEYs6qWU1S2E0tjHoxxwhTmEUQ8XxOjvXW_zkKVkGbwg8OyXFW3vtcNSjmyV4BUu7cG9lMNBNiQh7x4WZBMGf9ODf60XOQZJhHU_lLugd4xKLFyqn8qGam46cVP-jnkQfINq3KkvSWh0rr9Q0TJtsKda-Cny04r-XGSb0cSKtKsHnjgkUq51iLgqMavsf-Z2Dp7exnyDA40tNIEKvf-ovZQCZvc3vz1A4f0fTfEtwlQyAV9MlIaDu7-2Lijh0Y1Tmox76ipgGXYHPyRVGpKD2E8Gh5wymj9jVVnMmIEYIqnIeTW0FHf6CLaV1hbziS8reZmfidytR79XxVWIO3puMtYk72qpnR0HcIj2dR8DhkbdC_K6Li0p_k7A5wRmaSF4L4SkyxkihSvV7V-gJif-CgYEzldqB1CkePDs1RWnD3ZTANj8m2FGBBxPPNsWqgROhAAkDLatuyBfYnCB4DSNotVyBNe6oY
                )

        )

)
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-parse-a-json-file-in-php
How to parse a JSON File in PHP? - GeeksforGeeks
Parsing JSON data in PHP is simple and efficient. With the use of functions like file_get_contents() and json_decode(), you can easily load and process JSON data in your PHP applications.
Published   June 24, 2025
🌐
PHPpot
phppot.com › php › json-handling-with-php-how-to-encode-write-parse-decode-and-convert
JSON Handling with PHP: How to Encode, Write, Parse, Decode and Convert - PHPpot
In the above example of parsing JSON file data via PHP, we have used the file_get_contents() function. The file_get_contents() will not work on the server because of the security directives enabled with the PHP.ini configurations.
🌐
YouTube
youtube.com › watch
jQuery GET JSON from URL Tutorial: Retrieve data from a PHP script - YouTube
In this tutorial you will learn how to use jQuery to GET JSON from a URL. Recommended training (Free for 7 days) : https://juniordevelopercentral.com/treeho...
Published   September 24, 2018
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-return-json-from-a-php-script
How to Return JSON from a PHP Script ? - GeeksforGeeks
July 23, 2025 - <?php $jsonData = array( 'organization' ... json_encode($jsonData); ?> ... In this approach, we are using file_get_contents() to fetch JSON data from the specified URL ($jsonPlaceholderUrl), which in this case is the JSONPlaceholder ...