PHP: Telegram Bot: Insert line break to text message
1) If you develop your code in Windows/Linux OS, you can simply use enter in text:
$text = 'test 123
another text';
Thats all!
2) If your code run on Windows/Linux server, you can use PHP_EOL
constant instead of \n
:
$text = 'text 123 '.PHP_EOL.'yet another text';
3) And if you search for an OS independent soloution, you can use %0A
or chr(10)
for this purpose:
$text = 'text 123 '.chr(10).'yet another text';
There is a better way! The problem is because of URL encodings...
You can use normal PHP text using \n
but by passing it to urlencode
method, as follows:
$txt = urlencode("here is my text.\n and this is a new line \n another new line");
It works for me!