Hello! There are textarea on stanitsa used as a notebook where I write all sorts of notes

 первая строка вторая строка третья строка 

after saving it turns out

 первая строка\nвторая строка\n\nтретья строка 

also displayed in the database (field type TEXT).

Here's how to write and extract data:

 function change_note () { $note = (string)$this->request['note']; bb_update(Array('note' => DB()->escape($note),)); $this->response['html'] = 'сохраненo'; } 
 <script type="text/javascript"> ajax.change_note = function() { ajax.exec({ action : 'change_note', note : $('#note').val() }); }; ajax.callback.change_note = function(data){ $('#res_note').html(data.html); } </script> <table><tr> <th colspan="2"><h3>NOTE</h3></th> </tr><tr><td> <textarea rows=15 cols=150 id="note" name="note">{NOTE}</textarea> <br><input type="button" value="SAVE" onclick="ajax.change_note();"> <div id="res_note"></div> </td> </tr></table> 

$template->assign_vars(array("NOTE" => nl2br($note)));

I do not display the saved data in a separate block, but in the same textarea .

It is interesting that after the next save, another one is added to the existing one \

SAVE

первая строка\\nвторая строка\\n\\nтретья строка\nчетвертая

SAVE

первая строка\\\\nвторая строка\\\\n\\\\nтретья строка\\nчетвертая\nпятая

What do you need to do to display the result from the database without \n displayed (as a normal transfer) and why does the extra \ appear after the next saving of the note?

  • escape tries to secure the "\" service character by putting a "\" in front of it. So it turns out "\\". The next time you save, escapes two insecure "\\" characters from which you get "\\\\" - Dmitry Kozlov
  • What instead of escapes to use? - Alex31 2:41 pm
  • here it is necessary to look apparently the data in the change-note are already screened, where they are screened again - Dmitry Kozlov
  • Tried to replace \ n with pregrepleys on <br>. Changes, but again does not tolerate. But the problem with \ remains, if this slash is present in the text, then each time you save the text, an additional \ appears - Alex31
  • bb_update is that? and generally what is the backend? Php Any framework or own scripts? It seems that the bb_update function does not need shielding and does shielding somewhere inside of itself. Try without escape at all - Dmitry Kozlov

1 answer 1

 nl2br($note) 

I propose to remove it.

  • That with nl2br (), that without it is displayed the same way, I tried to clean it up - Alex31
  • @ D-side ok, I will consider - rjhdby