"\n" not working in text coming from mongo, but the concatened "\n" works

23 Views Asked by At

basically, i'm sending one message to chat API

// $n->mensagem = Lembre-me, contrato 156051 \n  \n\n mensagem: \naaaaaa

$mensagem = $n->mensagem . " \n\n\naaaa";

app(Rocketchat::class)->sendMessage(
    $n->getAlvo(), 
    $mensagem
);

and the result impress is:

Lembre-me, contrato 156051 \n \n\n mensagem: \naaaaaa

aaaa

only the concatened "\n" worked, how can i fix that?

result image

i tried to search for some responses in the internet and all i get is the nl2br but this don't work in my case

1

There are 1 best solutions below

0
Guilherme On

i just found the response, i don't know exactly why, but if you replace '\n' by "\n" it will work

str_replace('\n', "\n", $n->mensagem);

doing this the message was printed like

Lembre-me, contrato 156051

mensagem: aaaaaa