removing empty paragraphs and limit <br />

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cjkeane
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

removing empty paragraphs and limit <br />

Post by cjkeane »

Hi everyone,

I need a way to remove extra paragraphs and <br /> in a textarea.

it could appear as:
<br />
<p>&nbsp;</p>
<br />
<p>&nbsp;</p>
<p>&nbsp;</p>

or

<br />
<p>&nbsp;</p>
<p>&nbsp;</p>
<br />

and i need a way to remove all extra <br /> as i have seen this posting into the db as well:

<br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br />
SNivas
Forum Newbie
Posts: 3
Joined: Fri Sep 26, 2014 6:28 am

Re: removing empty paragraphs and limit <br />

Post by SNivas »

use margin: 0; to remove the spaces between paragraphs or empty paragraphs.

p { margin: 0; }

or

p { margin: 0 !important; }
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: removing empty paragraphs and limit <br />

Post by Celauran »

Give your users a WYSIWYG and this sort of thing becomes inevitable. You can try to strip out the <p>&nbsp;</p> using regex or str_replace or something, but "extra" <br>, especially with a WYSIWYG, is going to be a tougher nut to crack. What problems is it causing?
Post Reply