简体   繁体   中英

php - telegram bot message width

currently I'm working on a telegram bot in php and Yii2 framework. I want to send a message that has a fixed width in telegram. if i send "Hi!" it should fill a line like this image: 在此输入图像描述

is it possible? I want the spaces after message so <br> wont do that and breaks the line right after the word 'Hi'. can I do this without <code> tag? because this tag make the message like a line of code .

White space(s) and newline(s) at the two ends of the string are trimmed for a good reason. So, it is not possible to send the text with space or newline character(s) at any of the two ends, though you can put spaces at the end of the lines before the last character that's neither a space nor a newline.

Update #1 There is a trick though. You can add Zero-width non-joiner as the text to a <a> tag with empty href after any number of spaces you want. So the essential params for sendMessage method will be:

$text = 'hi‌‌‌‌‌‌‌‌‌‌‌‌                           <a href="">&#8204;</a>';
$chat_id = <your chat_id>;
$parse_mode = 'HTML';


在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM