-->

Remove BBCode tags and their content in PHP [dupli

2019-02-25 09:41发布

问题:

Possible Duplicates:
Recursive BBCode Parsing
Strip BBCode via RegEx

What is the best way to remove all BBCode tags of a string and their content in PHP?

回答1:

<?php
function stripBBCode($text_to_search) {
 $pattern = '|[[\/\!]*?[^\[\]]*?]|si';
 $replace = '';
 return preg_replace($pattern, $replace, $text_to_search);
}

echo stripBBCode($text_to_search);
?>

demo