5

当我将从mysql数据库读取的数据发送给电报用户时,用户得到下划线等而不是换行符。所以这样我就不能正确格式化消息文本。

如何格式化包含 4 个或更多可能答案的问题的电报消息?

还有什么我没想到的会发生变化?顺便说一句,我正在发送非英语字符。

$qsBody = $rowQuestion['body']; // This is what I read from database that contains some new line characters
$strReply = $qsBody;
$strSendMethod = "SendMessage?chat_id=$ChatId&text='$strReply'";
file_get_contents( BOT_TARGET_ADDRESS . $strSendMethod );
// The message received by user contains _ instead of new line.
4

3 回答 3

3

嗯,这很容易!我只需要在 url 中编码消息。

$qsBody = $rowQuestion['body']; // This is what I read from database that contains some new line characters
$strReply = $qsBody;
$strReply = urlencode($strReply ); // encode message
$strSendMethod = "SendMessage?chat_id=$ChatId&text='$strReply'";
file_get_contents( BOT_TARGET_ADDRESS . $strSendMethod );
// The message received by user contains _ instead of new line.
于 2015-08-20T07:15:12.977 回答
0

sendMessage 是小写的“s”。

 $qsBody = $rowQuestion['body']; // This is what I read from database that contains some new line characters
    $strReply = $qsBody; // set here your message with \n where you want a new line
    $strSendMethod = "sendMessage?chat_id=$ChatId&text='$strReply'";
    file_get_contents( BOT_TARGET_ADDRESS . $strSendMethod );

在这里试试https://telegram-bot-sdk.readme.io/docs/sendmessage

于 2016-11-11T13:43:12.803 回答
0

您可以使用如下代码:

$text = 'hi-how are you?_im fine.lets go';
$text = str_replace(array('_', '-', '.'), chr(10), $text);

代码,用换行符替换下划线_和字符。-.

于 2015-08-19T04:52:50.910 回答