Stack crawler Stack crawler - 29 days ago 8
PHP Question

How to generate new line character in telegram message?

When I send the data I read from mysql database to telegram user, the user gets underline and etc instead of new line character. So this way I can't format message text correctly.

How can I format a telegram message that is a question with 4 or more possible answers?

What else is going to be changed that I don't expect? By the way I'm sending non-english characters.

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

Answer

Well, it was very easy! I just had to encode message in url but no body told me to do it!

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