【发布时间】:2018-06-28 05:04:04
【问题描述】:
您好,我有要在本地主机上运行的脚本。 PHP中的代码,当我运行我的本地主机时,它说
解析错误:语法错误,第 23 行 /Applications/XAMPP/xamppfiles/htdocs/bot/course.php 中的意外“>”
这是代码:
<?php
ob_start();
$API_KEY = '';
define('API_KEY',$API_KEY);
function bot($method,$datas=[]){
$url = "https://api.telegram.org/bot".API_KEY."/".$method;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$datas);
$res = curl_exec($ch);
if(curl_error($ch)){
var_dump(curl_error($ch));
}else{
return json_decode($res);
}
}
$update = json_decode(file_get_contents('php://input'));
$message = $update- >message;
$text = $message- >text;
$chat_id = $message- >chat- >id;
if ($text =='/start') {
bot('sendMessage',[
'chat_id' => $chat_id,
'text'=> 'Welcome',
]);
}
第 23 行是 $message,我真的看不出有什么错误吗?
【问题讨论】:
-
尝试删除 -> 到 -> 之间的空格。您正在尝试访问属性。但现在你正试图从 >text- 中减去无效的 PHP 代码。