Break line row in <div> tag from database

I need to display an article from a database inside a <div>. This article was inserted into the database from a text box. My problem: I was not able to accurately display the structure that I inserted from the text box (including line break)

I tried the code below to replace the input character with <br>, but that didn't work

<div id="tmpId">${f:h(dto.accPassage)}</div>

<script>
    $(function(){
        $('#tmpId').html($('#tmpId').html().replace(/\n/g, '<br />'));
    })
</script>

I wonder if anyone can give me some clues to solve this problem.

Many thanks.

+3
source share
4 answers

, , , <pre> <div>.

<pre id="tmpId">${f:h(dto.accPassage)}</pre>

.

+9

, , ? , ( , ), PHP, , $output - , ,

$output = nl2br($output);

, !

+2

java, - , , .

public static String nl2br(String s) {
    return s.replaceAll("\n","<br/>");
}
// usage
nl2br("some\ntext"); //will return "some<br/>text"
0

<br> .

-1

Source: https://habr.com/ru/post/1765016/


All Articles