Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP获取网页内容_Php_Telegram Bot_Php Telegram Bot - Fatal编程技术网

如何使用PHP获取网页内容

如何使用PHP获取网页内容,php,telegram-bot,php-telegram-bot,Php,Telegram Bot,Php Telegram Bot,我正在使用PHP来管理我的电报机器人。基本上,Telegram添加了一项功能,允许用户在此url内从其机器人获取更新: 现在我想知道,我要搜索的机器人是否存在 因此,每当您键入错误的bot令牌号时,API页面将返回以下内容: {"ok":false,"error_code":401,"description":"Unauthorized"} 如果存在,页面将返回以下内容: {"ok":true,"result":[]} 正如你所看到的,为了知道机器人的存在,我必须获取这个页面的内容并确定一

我正在使用PHP来管理我的电报机器人。基本上,Telegram添加了一项功能,允许用户在此url内从其机器人获取更新:

现在我想知道,我要搜索的机器人是否存在

因此,每当您键入错误的bot令牌号时,API页面将返回以下内容:

{"ok":false,"error_code":401,"description":"Unauthorized"}
如果存在,页面将返回以下内容:

{"ok":true,"result":[]}
正如你所看到的,为了知道机器人的存在,我必须获取这个页面的内容并确定一些变量。那么,如何使用PHP实现这一点呢?

您可以使用:

$content = file_get_contents($url);
或者使用卷曲


您可以使用:

$content = file_get_contents($url);
或者使用卷曲



尝试使用file\u get\u contents(),它将返回您在浏览器中打开同一URL时看到的任何内容。你也可以看看这样做的方法,这样你就不必再发明轮子了;)

尝试使用file_get_contents(),它将返回您在浏览器中打开同一URL时看到的任何内容。你也可以看看这样做的方法,这样你就不必再发明轮子了;)

使用
get\u标题快速简便的两行程序

$headers=get_headers('https://api.telegram.org/bot/12345');
$active=$headers[0]=='HTTP/1.1 404 Not Found' ? false : true;
然后,您可以在布尔逻辑测试中使用
$active
继续处理或中止

if( $active ){/* do stuff */} else {/* go to the pub */}

使用
get_headers

$headers=get_headers('https://api.telegram.org/bot/12345');
$active=$headers[0]=='HTTP/1.1 404 Not Found' ? false : true;
然后,您可以在布尔逻辑测试中使用
$active
继续处理或中止

if( $active ){/* do stuff */} else {/* go to the pub */}

或者更容易使用?或者更容易使用?很好,但是现在我测试了这个
$ch=curl\u init(“https://api.telegram.org/bot“$token。”/getUpdates”)并没有写入
{“ok”:false,“error\u code”:409,“description”:“Conflict:在webhook处于活动状态时无法使用getUpdates方法”}
(这是我的bot更新的当前状态),而是写入:
{“ok”:false,“error\u code”:404,“description”:“Not Found”}
尝试回显/var\u转储你的url字符串,格式是否正确?是否缺少任何
/
?很好,但现在我测试了这个
$ch=curl\u init(“https://api.telegram.org/bot“$token。”/getUpdates”)并没有写入
{“ok”:false,“error\u code”:409,“description”:“Conflict:在webhook处于活动状态时无法使用getUpdates方法”}
(这是我的bot更新的当前状态),而是写入:
{“ok”:false,“error\u code”:404,“description”:“Not Found”}
尝试回显/var\u转储你的url字符串,格式是否正确?是否缺少任何
/