How to make line breaks when displaying text from a table field text? The data is cast through the text area, displayed via nl2br. But here only 1 transfer is shown, how to make it show both 2 and 3 transfers? Can do type

str_replace(" ", "<br>", $text); 

but this option turned out to be inoperative :( Also, in general, when a record is thrown into a database, 2 or more transferences are eaten, that is, only one remains. Can this be corrected?

    2 answers 2

    To make a transfer from textarea to html:

     <textarea>Текст. Дальше два переноса. И снова текст </textarea> 

    In php, try using the echo operator to do this too. For example:

     echo "<textarea>Текст. Дальше два переноса. И снова текст </textarea>"; 
    • I need not to text. region the text was displayed with the transfer, because there it is displayed as needed. Now the text is output with 1 transfer tag from the database, via nl2br. I need to have 2-3 or more transfers, where necessary. - rimlin
    • It is strange that nl2br () eats up all the new line translations. Try to use regular expressions and functions [preg_replace ()] [1]. [1]: php.net/manual/ru/function.preg-replace.php - evlanoff
    • @rimlin Sorry I misunderstood you. - atnartur

    If the data is entered into the database, then whitespace characters (space, tabulation, line breaks) should be escaped in the line from the text field so that they do not stick together into one. For MySQL, this is the mysql_real_escape_string () function, example:

     $mysql_result = mysql_query('INSERT INTO `table` (`text`) VALUES ("'.mysql_real_escape_string($_REQUEST['textarea']).'")'); 

    That is, the transfers disappear during input and not during withdrawal.