15 November 2019

Telegram Bot 1.1

biar yang ini https://bayu.blitarian.com/2019/11/telegram-bot-1.html bisa di baca secara normal oleh manusia pada umumnya. (https://en.wikipedia.org/wiki/Human-readable_medium).

aslinya seperti ini :


dari contoh diatas :


1
2
3
4
5
6
7
8
9
echo "<br>";
echo "ID : " .$data["result"][2]["message"]["from"]["id"];
echo "<br>";
echo "IS_BOT :" .$data["result"]["2"]["message"]["from"]["is_bot"];
echo "<br>";
echo "FIRST NAME :" .$data["result"][2]["message"]["from"]["first_name"];
echo "<br>";
echo "RESULT :" .$data["result"][2]["message"]["from"]["username"];
echo "<br>";

hasilnya (contoh):


php lengkapnya seperti contoh diatas :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php

//menggunakan curl

$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,"https://api.telegram.org/bot(TOKEN)/getUpdates");
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_TIMEOUT,3);
curl_setopt($ch,CURLOPT_HTTPGET,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);

$content=curl_exec($ch);

curl_close($ch);

$data=json_decode($content, true);

echo "<br>";
echo "ID : " .$data["result"][2]["message"]["from"]["id"];
echo "<br>";
echo "IS_BOT :" .$data["result"]["2"]["message"]["from"]["is_bot"];
echo "<br>";
echo "FIRST NAME :" .$data["result"][2]["message"]["from"]["first_name"];
echo "<br>";
echo "RESULT :" .$data["result"][2]["message"]["from"]["username"];
echo "<br>";

?>

nah bagaimana menampilkan keseluruhan data json nya ?

No comments: