Hos*_*ebi 45 php linefeed telegram-bot
"\n"并且"\r\n",在电报机器人发送的短信中进行测试,以创建换行符._使用它们后,将显示下划线,而不是显示换行符.
如何在机器人发送的电报信息中打印换行?
码
$txt = '?? ???? ?? ????? ???? ?? ??? ???? ???? 10 ?? ?? ?????? ???? ???? ??? ????? ????? ??.';
$txt .= " \n ";
$txt .= 'Thanks for joining, Every day at almost 18:30 GMT an intersting video will be sent';
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
Maj*_*jid 56
有一个更好的方法!问题是由于URL编码...您可以使用普通的PHP文本,\n但将其传递给urlencode方法,如下所示:
$txt = urlencode("here is my text.\n and this is a new line \n another new line");
Run Code Online (Sandbox Code Playgroud)
这个对我有用!
علی*_*رضا 32
1)如果您在Windows/Linux操作系统中开发代码,只需使用输入文本:
$text = 'test 123
another text';
Run Code Online (Sandbox Code Playgroud)
就这样!
2)如果您的代码在Windows/Linux服务器上运行,您可以使用PHP_EOL常量而不是\n:
$text = 'text 123 '.PHP_EOL.'yet another text';
Run Code Online (Sandbox Code Playgroud)
3)如果您搜索独立于操作系统的解决方案,您可以使用%0A或chr(10)为此目的:
$text = 'text 123 '.chr(10).'yet another text';
Run Code Online (Sandbox Code Playgroud)
对于未来的访客,我只在评论中引用@Dagon答案:
使用%0A将在电报消息中换行
在阅读并尝试了所有这些答案后,我只想发布我自己的解决方案。我在 Laravel 5.8 中有一个应用程序,它通过电子邮件和 Telegram 消息发送预订。
$telegramMessage =
"<strong>Reservation Request</strong>\n".
'<strong>Name:</strong> ' . $reservation->reserv_name . "\n".
'<strong>E-mail:</strong> <a href="mailto:' . $reservation->email . '"> ' . $reservation->email . "</a>\n".
'<strong>Phone:</strong> ' . $reservation->phone . "\n".
'<strong>Reservation Date/Time:</strong> ' . $reservation->reserv_date_time->format('d-m-Y H:i') . "\n".
'<strong>Number of people:</strong> ' . $reservation->number_of_people . "\n".
'<strong>Message:</strong> ' . $reservation->reserv_message . "\n";
Telegram::sendMessage([
'chat_id' => env('TELEGRAM_CHAT_ID', ''),
'parse_mode' => 'HTML',
'text' => $telegramMessage,
]);
Run Code Online (Sandbox Code Playgroud)
或多或少我已经使用了 Telegram API 允许的所有 html 标签。需要注意的是\n必须用双引号引起来。
| 归档时间: |
|
| 查看次数: |
53129 次 |
| 最近记录: |