【问题标题】:Parse error: syntax error, unexpected '>' [duplicate]解析错误:语法错误,意外'>' [重复]
【发布时间】: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 代码。

标签: php mysql xampp localhost


【解决方案1】:

我看到了你的这段代码

$message = $update- >message;
$text = $message- >text;
$chat_id = $message- >chat- >id;

试试

$message = $update->message;
$text = $message->text;
$chat_id = $message->chat->id;

【讨论】:

  • 您好,感谢您的回答,我按照您所说的做了,但上面写着注意:尝试在第 23 行的 /Applications/XAMPP/xamppfiles/htdocs/bot/course.php 中获取非对象的属性
  • 嗨,马赫。您的错误意味着您正在访问一个非对象,也许它是一个数组。试试 var_dump($message);die;看看它的属性,可能你需要 $message[0]->text 。
猜你喜欢
  • 2016-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-11
  • 1970-01-01
  • 2013-06-28
相关资源
最近更新 更多