Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

276
Visualizações
How to make line breaks when displaying the content of a textarea?

I'm trying to do a forum in php. I have a problem. I have a publish form with a textarea. Let's imagine that I fill it all.

When I make a line break (when I press space bar), with nl2br, in my database there are <br> tags added. But when I just type and there is an auto line break, there is no <br>.

How can I do to, for example, at the end of 100 chars, there is an auto line break (that adds a <br> in the database. I've tried in Javascript but I didn't found a correct answer.

With

with <br>

In the database

Without

auto line break in textarea (no <br>)

in the database

Problem:

in the forum (text outside of the div

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

First part about PHP, I am also creating PHP website now but it's social media, and here how I did to make line breaks and also to escape chars like " or \ in my chat.

$letter = join("", explode("\r\n", $letter));
$letter = join(" \\\\ ", explode("\\", $letter));
$letter = join("\\\"", explode("\"", $letter));
$stmt = $mysqli->prepare("INSERT INTO Chat (sender, recipient, msg, date) VALUE (?, ?, ?, ?)");
$stmt->bind_param("ssss", $sender, $recipient, $letter, $dateofletter);
//$conn->query($sql);
$stmt->execute();
$mysqli->close();

and about the text too long try these

word-wrap: break-word;
word-break: break-all;

But if you want to exactly have the same line-breaks which user typed, then simply don't use CSS word break and replace write this $letter = join("<br>", explode("\r\n", $letter)); instead of $letter = join("", explode("\r\n", $letter));

or you may need $letter = join(htmlspecialchars("<br>"), explode("\r\n", $letter));

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda