PHP Add Paragraphs to all except those in tags

I’ve been trying to find a PHP BB Code parser that fits my website.

Basically I wanted to add paragraph tags to any text (retrieved from a database) not inside a tag (tags like pre+code+blockquote+etc should be left untouched).

My Text in the database would look like this

This is a paragraph
     This is another paragraph

as you can see it can spread out over multiple lines, or stay on one line.

This is a paragraph

I found this one

$content = preg_replace('/[^\r\n]+/', "<p>$0</p>", $content);

But this adds p tags inside elements such as pre+code.

Any suggestions on a better solution?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s