Question : how to replace all any chr(10)/chr(13) _not_ within html tags with a <br>

I have a textarea box that submits to my mysql db. This data is later displayed on a page.

A user can put in plain text. A user can put in HTML. A user can put in both plain text above, and then HTML below.

Normally, if this was just plain text I would just use the old handy replace all chr10 and chr13's with <br>.

However, I do not want to replace the chr10s and chr13s with br's if it is html.

Is there a small script that someone knows that can achieve this?

Here is an example of what could be put in a box:

<textarea>

Line 1

Line 2
Line 3

<div>
Line 4<br>
<br>
Line 5<br>


Line 6
</div>

</textarea>

displays:

Which would display as:

Line 1

Line 2
Line 3

Line 4

Line 5
Line 6

Answer : how to replace all any chr(10)/chr(13) _not_ within html tags with a <br>

Ok I will give you an idea, use css to do that...
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
<style>
#display br.added
{
display:none;
}
#display>br.added
{
display:block;
}
</style>

<textarea cols=20 rows=10 id="comments"></textarea>
<br>
<button onclick="format()">display below</button>
<br>
<div id="display"></div>

<script>
        function format()
        {
                var comm = document.getElementById("comments").value;
                //comm = comm.replace(/<br>.\n/g,"\n").replace(/<br\/>.\n/g,"\n");
                comm = comm.replace(/\n/g,"<br class='added'/>");
                document.getElementById("display").innerHTML = comm;
        }
</script>
Random Solutions  
 
programming4us programming4us