View Full Version : Outputting p tags with regex

10-23-2004, 04:19 AM
I've written my own blog software using portions of WordPress (I didn't need all the functionality of Wordpress), and i've hit a snag with autop function. I've never been able to get my head around the correct syntax for regular expressions, so i'm at a loss.

The function puts p tags around every line that ends with a line break (\n) in the database. However some of my lines end with one line break, and others with two, and when I write text like this



without intending for there to be a paragraph break after the first line, it's outputted as




My idea was to modify the function code so that it would output a padded p tag around lines wth a double line break, and a class that removes the padding on the p tags that surround lines with only one line break.

My current attempt looks something like this

preg_replace('/\n?(.+?)\n/',"<p class=\"singlebreak\">$1</p>",$pee);

but of course it doesn't work how i'd like it to. Most of the methods i've tried result in missing p tags, incorrectly nested tags, or preg_replace function errors. The code I just posted results in all p tags having a single break, which obviously isn't what i'm trying to accomplish.

Any help on this will be greatly appreciated, as i've been trying to figure this out for almost two days without any success.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum