How to create a new line symbol in a telegram message?

When I send the data that I read from the mysql database to telegram the user, the user gets an underscore, etc. instead of a new line character. Therefore, I cannot format the message text correctly.

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

What else will change that I do not 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. 
+4
source share
3 answers

Well, that was very easy! I just had to encode the message in the 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. 
+3
source

you can use the following code:

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

replace the underscores with _ , - and . line breaks.

0
source

sendMessage has an "s" in lowercase.

  $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 ); 

try here https://telegram-bot-sdk.readme.io/docs/sendmessage

0
source

All Articles