Text not inserting line break

Asked

Viewed 46 times

1

I did a search and found no post about the problem I’m facing.

I’m running a database search and writing on the screen what I find. But when the text is displayed it is not inserting line break, so the text gets all in one line.

Below I put the images of the problem and how the implementation is done (An Excerpt).

<div class="row">  
  <div class="col-12 mb-3 text-center">
     <?php echo $results['descricao']; ?>
  </div>
</div>

inserir a descrição da imagem aqui

1 answer

1


Unless the text in the database is already marked with HTML, you will have this "casing" on the screen. If you want to display the text in its original spacing and line layout, even if it is not marked with HTML, surround it with the tag pre.

It is quite common to process the database text before displaying it. For example, you can load the text into an array, divided into paragraphs. Then print each element of this vector (a paragraph) with the paragraph HTML element:

$paragrafos = explode("\n\n", $texto);
foreach($paragrafos as $paragrafo) {
  echo '<p>' . $paragrafo . '</p>';
}

Take a look at explode and foreach.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.