-2

Hi i have script that i want to run on my localhost . the code in PHP , and when i run my localhost, it says

Parse error: syntax error, unexpected '>' in /Applications/XAMPP/xamppfiles/htdocs/bot/course.php on line 23

this is the code:

<?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',
    ]);
}

Line 23 is $message, I really dont see any wrongs there ?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
MRJ
  • 29
  • 8
  • 4
    Try to remove the whitespaces from - > to ->. You are attempting to access a property. But right now you are trying to substract from >text- Which is invalid PHP code. – Willi Jan 19 '18 at 01:41

1 Answers1

1

I saw this code of yours

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

try

$message = $update->message;
$text = $message->text;
$chat_id = $message->chat->id;
MiksMeister
  • 418
  • 2
  • 8
  • 20
  • Hi thanks for your answer, I did what you said but it says Notice: Trying to get property of non-object in /Applications/XAMPP/xamppfiles/htdocs/bot/course.php on line 23 – MRJ Jan 19 '18 at 20:45
  • Hi Maher. Your error implies that you are accessing a non-object, maybe it was an array. Try var_dump($message);die; and see it's property, probably you need $message[0]->text for that. – MiksMeister Jan 21 '18 at 10:27