123321 - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of 123321.php

  1. <?php
  2.  
  3. // Замените YOUR_BOT_TOKEN на токен вашего бота
  4. define('BOT_TOKEN', '6690344501:AAEvH0OZc_xMJVhT6OIIRvhUgj4Ql1-tlQ4');
  5.  
  6. // Задаем URL для API Telegram
  7. $api_url = 'https://api.telegram.org/bot' . BOT_TOKEN . '/';
  8.  
  9. // Получаем данные о сообщении от пользователя
  10. $update = json_decode(file_get_contents('php://input'), true);
  11.  
  12. // Получаем ID чата и текст сообщения
  13. $chat_id = $update['message']['chat']['id'];
  14. $message_text = $update['message']['text'];
  15.  
  16. // Отправляем ответное сообщение пользователю
  17. sendMessage($chat_id, "Вы написали: $message_text");
  18.  
  19. // Функция для отправки сообщения пользователю
  20. function sendMessage($chat_id, $message) {
  21.     global $api_url;
  22.     $params = [
  23.         'chat_id' => $chat_id,
  24.         'text' => $message,
  25.     ];
  26.     $url = $api_url . 'sendMessage?' . http_build_query($params);
  27.     file_get_contents($url);
  28. }
  29.  
  30. ?>
File Description
  • 123321
  • PHP Code
  • 18 Feb-2024
  • 1.01 Kb
You can Share it: