The specific fields in our mysql db seem to contain newlines, so if I SELECT, for a single SQL call, something like the following will be returned:
Life to be sure is nothing much to lose But young men think it is and we were young
If I want to keep line breaks when displaying this field on a web page, is it a standard solution to write a script to replace '\ n \ r' with br HTML tag or is there a better way?
Thank!
Assuming PHP is here ...
nl2br()adds in <br />for everyone \n. Remember to avoid content first to prevent XSS attacks. See below:
nl2br()
<br />
\n
<?php echo nl2br(htmlspecialchars($content)); ?>
HTML - . , , (, <pre> white-space:pre). HTML <br> . , xA (newline, linefeed, LF, \n) / xD ( , CR, \r) HTML <br>.
<pre>
white-space:pre
<br>
xA
xD
\r
"\n" "<br>".
"\n"
"<br>"
<pre>.. </pre>.
</pre>
Source: https://habr.com/ru/post/1783129/More articles:What is the easiest way to make configuration files in Java? - javaNested ERB template templates such as Liquid? - layoutMySql: разумно ли использовать "представление", или я бы лучше денормализовал свою БД? - mysqlРезультат Json для html (Newline) - jsonHow to visually display b-tree in java? - javaWhy doesn't font color adjustment work? - htmlEF4 Include () with projection - linq-to-entitiesNo query results - sqlИзменение цвета текста для исключений в LogCat - androidПочему эти переменные, по-видимому, меняют тип? - cAll Articles