-1

using this php gives error 500, any help is appreciated.

what i want is to make the below URL behave like--- api.telegram.org/bot1A/sendMessage?chat_id=@mychannel&text=Hellow

<?php

$msg= Hellow
$response = file_get_contents("https://api.telegram.org/bot1A/sendMessage?chat_id=@mychannel&text=".echo $msg->plaintext;  );
// Do what you want with result
?>
Baba dook
  • 1
  • 1
  • 500 Internal Server Error is a generic error message informing you that the server crashed while processing the request. Beyond that, it's (intentionally) meaningless, and is of very little use for debugging. You need to check the PHP error log to try and find the underlying exception message. Once you've got that, you stand a chance of identifying the problem. – ADyson Jan 11 '21 at 11:00
  • 1
    But I can tell you now that you have some trivial syntax errors - `$msg= Hellow` needs a `;` at the end. And also you can't write `echo` inside another string, or put a `;` in there. `echo $msg->plaintext;` should just be `$msg->plaintext` since you're concatenating it. Please use an IDE or text editor which understands PHP and which would highlight these problems to you before you even tried to run the code. There are many free ones available. – ADyson Jan 11 '21 at 11:01
  • Hello ADyson, thanks for the reply, here is the error [11-Jan-2021 10:55:51 UTC] PHP Parse error: syntax error, unexpected '$response' (T_VARIABLE) in /home/bpr7142ayake/public_html/snap/bot/bot.php on line 4 – Baba dook Jan 11 '21 at 11:01
  • 1
    See this guide for general advice: [PHP parse/syntax errors; and how to solve them](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – ADyson Jan 11 '21 at 11:04
  • dear ADyson, I would like to make the URL to behave like https://api.telegram.org/bot1A/sendMessage?chat_id=@mychannel&text=Hellow – Baba dook Jan 11 '21 at 11:06
  • 1
    It should be just `$msg= Hellow; $response = file_get_contents("https://api.telegram.org/bot1A/sendMessage?chat_id=@mychannel&text=".$msg);`. Not sure why you put `echo` in there, or where you think `->plaintext` is coming from - $msg is just a string, it doesn't have any properties like that, it's not an object. I think you need to make some more basic study of PHP before you worry about calling APIs and all that. – ADyson Jan 11 '21 at 11:12
  • ADyson my man, You're a life saver, thanks a ton buddy. God bless, this solved the issue. – Baba dook Jan 11 '21 at 11:14
  • 1
    No problem. Like I said, this is really basic syntax and you need to make sure you understand these basics before you move on. And please use an IDE or text editor which can highlight PHP syntax errors for you. – ADyson Jan 11 '21 at 11:15

1 Answers1

-1

Hellow needs to be quoted if a string or trailing parenthesis need to be given if its a function call, if its the latter convention is not to have a capital letter as the first letter in a functions name.

$msg = 'Hellow';

or

$msg = Hellow();

You can also drop the echo inside the file_get_contents argument, you wont need it

adrianp
  • 320
  • 2
  • 9