Remove BBCode tags and their content in PHP

Hamid picture Hamid · Jul 21, 2011 · Viewed 7.4k times · Source

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?

Answer

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

echo stripBBCode($text_to_search);
?>

demo