I have a function at the moment which will take the contents of a <textarea> form field, and replace carriage returns with an HTML <br /> tag,

Assume the textarea, named "this" contains:

Code:
Therefore, all projects can be broken down into 8 standard processes (according to the Prince2 methodology):

And so on and so forth
Then I would do this - feed it through a crappy function:

Code:
Function linebreak2(str)
    linebreak2 = Replace(str, "'","''")
    linebreak2 = Replace(linebreak2, chr(10), "<br />")
End Function
Then when I do a view-source on the output of the function, the contents of the textarea look like this:

Code:
Therefore, all projects can be broken down into 8 standard processes (according to the Prince2 methodology):
<br />

<br />And so on and so forth
That's not TOO bad - what I would really like to do is to find a function which will wrap and string in <p> tags, so the above would instead become this:

Code:
<p>Therefore, all projects can be broken down into 8 standard processes (according to the Prince2 methodology):</p>

<p>And so on and so forth</p>
That would be great - but the trick is that the function should only wrap text strings in <p> tags when they are empty strings.

For example, if the user entered some text into the textarea like:

Code:
<h1>Heading</h1>

And so I said this and that and the other

<blockquote>This is a blockquote</blockquote>

And I really liked flying gliders
The function should be able to ignore the tagged lines, and just wrap <p> tags around the empty strings, to generate:

Code:
<h1>Heading</h1>

<p>And so I said this and that and the other</p>

<blockquote>This is a blockquote</blockquote>

<p>And I really liked flying gliders</p>
I'm no coder, so I am realy stuck working out how this would work, because the function must do 2 things:

1. Wrap <p> tags around any empty lines
2. Ignore lines which already start with a tag of some sort.

Any advice greatly appreciated

Thanks!

Jim