php - Saving line breaks with preg_replace -


This code is used to save line breaks in the text field input in my database:

  $ Input = pre__reale ("/ (\ n) + / m", '\ n', $ input);   

On checking the input in the database, the line breaks are actually saved.
But the problem is that when I want to resonate it, the line break does not appear in the output, how can I protect the line breaks in the input and also resonate them I & lt; Pre & gt; & Lt; / Pre & gt; .

You do not want to use

You can assign the actual sequences of the new code to $ input \ n (backslash + n) - There is no new line, they need to convert back to Newline while reading from the database. Although I suspect that you intend to keep these real new lines in the database and instead use a double quoted string ...

  $ input = preg_replace ('/ ( \ N) + / m ', "\ N", $ input);   

Note that I have replaced the first string delimiter with the quotation marks and the second string with double quotes. To indicate a new line (ASCII 10), there is a special sequence in a regular expression, but it saves one character in PHP to give the same signal - both sometimes sometimes can do.

Comments