如何在电报信息中生成新的行字符?

时间:2015-08-18 13:46:25

标签: php telegram

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

3 个答案:

答案 0 :(得分:3)

嗯,这很容易!我只需要在网址中对邮件进行编码,但没有人告诉我这样做!

$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.

答案 1 :(得分:0)

你可以使用这样的代码:

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

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

答案 2 :(得分: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