如何在电报消息中生成换行符?

How to generate new line character in telegram message?

当我将从 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.

您可以使用这样的代码:

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

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

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

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