Forum Moderators: coopster

Message Too Old, No Replies

Formatting input HTML

         

Speeps

3:10 pm on Aug 21, 2006 (gmt 0)

10+ Year Member



I'm working on a blogging platform, and I'm struggling with the final output (what the end users/web visitor sees).

I've got to the stage where the data stored in the database in 100% correct.

My problem is converting line breaks to <br /> and <p></p>.

An example database stored entry:


<h2>A Testing title!</h2>

A list:

<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>

Another paragraph.

This is how I'd like it to be displayed to viewers:


<h2>A Testing title!</h2>

<p>A list:</p>

<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>

<p>Another paragraph.</p>

I've tried: nl2br and replacing double '<br />' to '</p><p>', but this messes up the HTML lists and sometimes H tags.

What I really want is a nl2br function that doesn't work between block level elements.

Can anyone point me in the right direction?

the_nerd

8:57 pm on Aug 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like it's too late at this stage - why don't you handle the data and formatting before they go into the database?

You code will probably contain lots of line breaks, so it will be hard to define which should be replaced.

nerd