How to add new line breaks in Telegram bot messages using PHP

I’m working on a PHP Telegram bot and having trouble with line breaks in my messages. When I try to use "\n" or "\r\n" to create new lines, they don’t work properly. Instead of showing actual line breaks, I see underscore characters _ in the message.

I need to send a message that has text in two different languages on separate lines. Here’s what I’m trying to do:

$message = 'Welcome to our channel! We send daily content at 9 PM.';
$message .= "\n";
$message .= 'Join us for amazing videos and updates every evening!';

The problem is that the line break doesn’t show up correctly when the bot sends the message. The text appears all on one line with strange characters instead of being split into two lines like I want.

What’s the correct way to add line breaks in Telegram bot messages when using PHP? Is there a special character or method I should use instead?

Those underscores mean Telegram’s trying to parse your message as Markdown and failing. I hit this exact issue building a multilingual bot - when Markdown syntax breaks, Telegram just shows underscores instead.

Quick fixes: Set parse_mode to null in your sendMessage call, or switch to HTML formatting. If you go HTML, use <br> tags instead of \n for line breaks.

Also check if you’re URL encoding the message first - that can break your line breaks. I’ve found %0A (URL encoded newline) works better than \n sometimes, depending on how you’re hitting Telegram’s API.

those underscore chars look like telegram’s markdown parser messing up. send your message in plain text first - see if linebreaks work at all. if you’re using sendMessage API, don’t set parse_mode to markdown or html while testing. also check your json encoding - sometimes \n gets double-escaped to \n and breaks everything.

Had this exact problem last year with my notification bot. Your PHP string escaping is probably the culprit. Make sure you’re using double quotes, not single quotes - ‘\n’ won’t work with single quotes in PHP. I switched to PHP_EOL instead of manual line breaks and that fixed it. PHP_EOL picks the right line ending for your system automatically. Check your file encoding too - needs to be UTF-8 without BOM. I had weird characters showing up in Telegram because of encoding issues. Still getting underscores? Try a simple test with just ‘line1’ . PHP_EOL . ‘line2’ to see if it’s your string concatenation or something else breaking it.