Forum Moderators: coopster

Message Too Old, No Replies

Help inserting <p> tags into text

Inserting <p> into a text/html mix

         

thing3b

10:12 am on Nov 17, 2005 (gmt 0)

10+ Year Member


I am having trouble writing this in PHP and was wondering if anyone could help me.

On my website I have a basic system where I can type HTML code into a box and it appears on a webpage. As simple as that.

The problem is that a lot of the items I am putting into the site are Text based. They are separated into paragraphs by double returns (though the line in-between may have white space on it like spaces). It is very slow to put all the paragraph tags in.

What I would like to be able to do is to be able to use html tags like li, ol, table, tr, td th, a, b, c, h1 etc without having to put the paragraph tags in. I then would like php to place paragraph tags around the paragraphs and place a br where there is only one return (but only do this outside the previously mentioned tags).

Can anyone point me to code that could do this,
or show me how it could be done?

Thanks,
PHP noob

coopster

12:11 pm on Nov 17, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have you considered str_replace() [php.net] or nl2br() [php.net]?

thing3b

9:05 pm on Nov 17, 2005 (gmt 0)

10+ Year Member



The problem witht the nl2br function is that it will do stupid things like put a br between the table and tr tags if they are on separate lines. (If I am guessing right)