当我将从mysql数据库读取的数据发送给telegram用户时,用户将得到下划线等,而不是换行符。所以这样我就不能正确地格式化消息文本。
如何格式化一个包含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.

最佳答案

好吧,很简单!我只需要在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.

09-12 06:12