QuestionsPHP remove specific tags with line break
mmWebetutorial Staff asked 2 weeks ago

// define ALLOWED_TAGS somewhere in your program
$ModifiedContent = strip_tags($Content,ALLOWED_TAGS);

// Consolidate line breaks
$ModifiedContent = preg_replace(“/(\r\n¦\n¦\r)/”, “\n\n”, $ModifiedContent);
$ModifiedContent = preg_replace(“/\n\n+/”, “\n\n”, $ModifiedContent);
// Wrap paragraphs with paragraph tags
$ModifiedContent = preg_replace(‘/\n?(.+?)(\n\n¦\z)/s’, “<p>$1</p>\n”, $ModifiedContent);
// Fix other tags that got wrapped in paragraph tags
$ModifiedContent = preg_replace(‘!<p>\s*(</?(?:code¦table¦tr¦td¦ul¦ol¦li¦pre¦select¦form¦blockquote¦dl¦dd¦dt¦p¦h[1-6])[^>]*>)!’, “$1”, $ModifiedContent);
$ModifiedContent = preg_replace(‘!(</?(?:code¦table¦tr¦td¦ul¦ol¦li¦pre¦select¦form¦blockquote¦dl¦dt¦dd¦p¦h[1-6])[^>]*>)\s*</p>!’, “$1”, $ModifiedContent);

Your Answer
Enter email and password to comment or answer
Not the answer you are looking for? Browse other questions tagged or ask your own question.