removing empty p tags from CKeditor entries

Subject:

When using CKeditor any line breaks br as in hitting enter will cause an extra and emtpy p tag.  makes sense for the markup to give a formatted look.

I want them removed

2015-04-09 17:20:05gstlouis

CKeditor will inject a   in the p tag if empty which means it isn't really empty so doing a quick jQuery won't work,

 

a string replace with reg expression does the trick

//this regular expression will remove empty P's with   in it.

  • $pattern = "/<p[^>]*>&nbsp;<\/p[^>]*>/";

 

echo preg_replace($pattern, ' ', $variable or target);

gstlouis
vote
2015-04-09 17:23:39

this has a list of all the buttons you can remove with

config.removeButtons

http://ckeditor.com/comment/123266#comment-123266

gstlouis
vote
2015-04-09 18:04:28