Remove BBCode tags and their content in PHP [duplicate]

穿精又带淫゛_ 提交于 2019-12-31 01:25:20

问题


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



来源:https://stackoverflow.com/questions/6777257/remove-bbcode-tags-and-their-content-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!