{ Trimming Empty Paragraph Tags }

Was working with content put into Drupal which, for some reason, had empty paragraphs. Thought I’d write a function to just get rid of those for me. What you’d want to do is something like:

$regex = '

[[:space:]]*

'; return ereg_replace($regex, '', $str);

This says, a p tag, followed by zero or more spaces, followed by a /p tag, it going to get replaced with an empty string. Gone.

Okay, that’s all well and good, but it’s not working, dude. I have found that sometimes what looks like a space is not actually a space. It may be the malicious combination of two characters, with the ascii codes of 194 and 160. They pretend to be a space. I think this is something MS Word does. Don’t ask me why. If this is the case, try this:

$regex = '

' . chr(194).chr(160) . '

'; return ereg_replace($regex, '', $str);

1 thought on “Trimming Empty Paragraph Tags

Leave a Reply

Your email address will not be published. Required fields are marked *