[英]How to get the name of Telegram bot with PHP
I'm trying to make a custom management system for Telegram bots so that I can be able to send and read updates easily.. But my main problem is that I don't know how to retrieve data from an array.我正在尝试为 Telegram 机器人制作一个自定义管理系统,以便我能够轻松发送和读取更新。但我的主要问题是我不知道如何从数组中检索数据。 let me explain this in depth so you can understand what I'm talking about.
让我深入解释一下,这样你就能明白我在说什么。
Basically when I try the getme
command, I get this:基本上当我尝试
getme
命令时,我得到了这个:
{"ok":true,"result":{"id":275700102,"first_name":"photoshop_post_production","username":"post_pro_bot"}}
So I converted this into an array using Php and it goes like this:所以我使用 PHP 将其转换为一个数组,它是这样的:
$_SESSION['website'] = "https://api.telegram.org/bot";
$_SESSION['url'] = "https://api.telegram.org/bot".$_SESSION['token'];
$_SESSION['me'] = file_get_contents($_SESSION['url']."/getme");
$_SESSION['meArray'] = json_decode($_SESSION['me'], TRUE);
So as you can see I have an array called meArray
and if I print_r
it ,this will be shown:所以你可以看到我有一个名为阵列
meArray
,如果我print_r
话,这将是图所示:
Array ( [ok] => 1 [result] => Array ( [id] => 275700102 [first_name] => photoshop_post_production [username] => post_pro_bot ) )
So basically I don't know how to take out the username or other information that I want from this array.所以基本上我不知道如何从这个数组中取出我想要的用户名或其他信息。 I have tried several things but no success till now.
我已经尝试了几件事,但直到现在都没有成功。
So, should be:所以,应该是:
$_SESSION['meArray']['result']['username']
Try this.尝试这个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.