How to put line breaking in a textarea?

Asked

Viewed 14,718 times

6

When I’m going to change or include some data from a textearea I wanted you to save the line breaks. Also, when you show in a textarea before the data that already exist I wanted to show with the lines breaks.

Then I’ll bring you two together textarea and saved at the bank. I’ve looked at the break codes and tried here and it didn’t work, someone can help me?

Observações:</p>
<p>
    <textarea name="obs" cols="150" rows="10" style="resize:none" readonly ><?php echo $obs; ?></textarea> <!-- Aqui somente mostra os dados do banco e queria com as quebras de linhas. -->
</p>

<br>
Para adicionar dados usar o campo abaixo.
<textarea name="obs1" rows="10" cols="150" style="resize:none" ></textarea> <!-- Aqui a pessoa digita o que irá adicionar com o texto acima e queria com quebra de linha. -->
  • 1

    Tried to use the nl2br($obs) ?

  • i put in the first textearea <?php echo nl2br($Obs); ? > and not breaking the lines. in the first you have to show the lines in each separate row and in the second I type the text and if I give enter I want you to save with the breaks. however as I put together the two text area have to have a line break between them

  • But you’re saving the text in the bank using the nl2br ?

  • not pq already tried by and not accepted error.

  • It makes a mistake? But it shouldn’t... so you have to save with nl2br and pull with nl2br.

  • did Aki and even gave. however it is showing the <br> inside the text area is like that? texte5<br /><br /><br /><br />&#Xa.

  • No, it’s not like that. Do it like this: $quebras = array("<br />","<br>","<br/>"); &#xA; $text = str_ireplace($quebras, "\r\n", $obs);. Then take the nl2br and makes echo $obs in the textarea to see.

  • the <br> continues to appear inside the text area

  • How did you do ? I got it wrong in the end. Yeah echo $text.

  • I had put it the way you say I changed it to $text and it worked. It’s the junction of textarea1 and 2 that’s stuck. type I put together $Obs with $Obs1 and rewrite in bank pq I want to add information I show q already has and in the bottom field write what needs to add and then together the two at the end... I was doing differently but as I know they will do wrong to dismembering.

  • I’m doing Aki test and as I edit the information it’s putting line break more than it should. type instead of skipping one as I add information it’s putting more of a line break in the data anrteriores

  • Edit your question and enter your current code.

  • 1

    mexi Aki and I managed to solve thanks!!

  • Can you give me another hand? I need to show this $Obs q field I picked up in the textarea but without being inside it and with the line breaks

  • Just take the textarea not and use the variable the same way.

  • i took out the textarea and ta showing everything in a row and it’s not breaking.

  • got put the <?php echo nl2br($text); ? > and was, hj ta hard to think....

Show 12 more comments

3 answers

4

Save to database with line breaks from <textarea>:

str_replace("\n",'<br />', addslashes(htmlspecialchars($_POST['valor']
// OPCIONAL: addslashes é para conversão do caracter ' e não dá conlflito no BD
// OPCIONAL: htmlspecialchars é para não permitir caracteres especiais

To take the value of <textarea> in the database do so:

str_replace('<br />', "\n", $valor);

3

You can put using:

Echo nl2br($row['campo']);
  • with Row does not work not accept

2

you can concatenate your string with &#10;

<textarea cols='60' rows='8'>Primeira Linha.&#10;Segunda Linha</textarea>

Browser other questions tagged

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