I am using ColdFusion 9.
I am outputting a chunk of text from a database to be directly into a web page. I don’t want users to have to write HTML and screw things up. So, I am having them insert a double at sign “@@” to denote a new paragraph. Data is stored like this:
@@This is my first paragraph. @@This will be my second paragraph. @@This is my third.
What I want to do is create a function that will turn the above block of text into the block of text below:
<p>This is my first paragraph.</p>
<p>This will be my second paragraph.</p>
<p>This is my third.</p>
I will never know whether the user actually used any @@ signs or not. If they didn’t, I’ll need to wrap the entire block in a p tag.
My first thought is to do this:
- Wrap the entire block into a p tag.
- Replace the first occurrence of @@ with “” (nothing).
- Replace every other occurrence of @@ with
</p><p>
Is this the right way of accomplishing this task?
REReplace(your text, "@@([^@]+)", "<p>\1</p>", "all");should sort it!