skip to Main Content

i use a php post to get the number of users in the telegram group

<?php
$post = array(
'chat_id'=>$chat_id);
$ch = curl_init("https://api.telegram.org/bot$tokken/getChatMembersCount?");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING,"");
header('Content-Type: text/html');
$posres = curl_exec($ch);
$data1 = json_encode($posres);
echo $data1;
?>

the response are array :

{"ok":true,"result":3}

how can i access the result value i tried echo $data1[19]; this only give the index position value
thank you

2

Answers


  1. The response is JSON, so you need to use json_decode() to convert it to a PHP array or object.

    $data1 = json_decode($posres);
    echo $data1->result;
    
    Login or Signup to reply.
  2. Just in case Your response is array of object

    echo $data1['19']->result; this should give 3 according to your question

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search