Trim Empty Paragraph Tags at Beginning & End of String

/ Published in: PHP
Save to your folder(s)

Useful for preparing content generated by CKEditor

Copy this code and paste it in your HTML
  1. function paragraph_trim($content) {
  2. $result = preg_replace('!(^(\s*<p>(\s|&nbsp;)*</p>\s*)*|(\s*<p>(\s|&nbsp;)*</p>)*\s*\Z)!em', '', $content);
  3. return $result === NULL ? $content : $result;
  4. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.