A
A
Alex Rave2020-05-24 11:52:31
PHP
Alex Rave, 2020-05-24 11:52:31

How to store the result from an external reference into a variable?

There is an external resource that issues an array using a link
https://api.deezer.com/search?q=LUCKY%20LUKE%20HYP...
It is required to save the contents of "cover_medium" to a variable
Please tell me how to implement this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OxCom, 2020-05-24
@Rocketdock

I do not like this way, but the essence will be clear:

<?php
$payload = \file_get_contents('https://api.deezer.com/search?q=LUCKY%20LUKE%20HYPNOTIZING');
$payload = \json_decode($payload, true, 512, JSON_THROW_ON_ERROR);
$media   = $payload['data'][0]['album']['cover_medium'] ?? 'media_not_found.jpg';

If you need to pass headers and other magic, then I advise you to use cURL or a good Guzzle wrapper

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question