I
I
Igor2018-11-22 17:51:48
PHP
Igor, 2018-11-22 17:51:48

How to select options in json_decode in php?

json_decode returns an array with data when I make a selection - the variable is empty:

<?php
header('Content-Type: text/html; charset= utf-8');

$token = 'МОЙ ТОКЕН';
 $api = 'https://api.telegram.org/bot' . $token;
 
    
    $output = json_decode(file_get_contents($api . '/getUpdates'), TRUE);
    
    //var_dump($output);
    $message = $output['message']['text'];
    echo 'Текст' . $message;
    
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Arkh, 2018-11-22
@m0pfin

What does var_dump($output); show?
The variable is empty because there are no such keys in the array and will not be, because getUpdates returns something else.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question