如何从方括号和括号之间删除文本?
例如,我需要
__CODE__
成为
__CODE__
这是我正在尝试使用的东西,但它没有做到这一点
__CODE__
我结束了
__CODE__
谢谢
我正试图在我的脚本中解析BBCode.现在,它无缝地工作,直到我尝试缩进BBCode不仅仅是粗体或下划线 - 例如剧透,网址,字体大小等 - 然后它搞砸了.这是我的代码:
function parse_bbcode($text) {
global $db;
$oldtext = $text;
$bbcodes = $db->select('*', 'bbcodes');
foreach ($bbcodes as $bbcode) {
switch ($bbcode->type) {
case 'simple': {
$find = '{content}';
$replace = '${1}';
$text = preg_replace(
'/\['.$bbcode->tag.'\](.+)\[\/'.$bbcode->tag.'\]/i',
str_replace($find, $replace, $bbcode->html),
$text);
break;
}
case 'property':
case 'options': {
$find = array ( '{property}', '{content}' );
$replace = array ( '${1}', '${2}' );
$text = preg_replace(
'/\['.$bbcode->tag.'\=(.[^\"]*)\](.+)\[\/'.$bbcode->tag.'\]/i',
str_replace($find, $replace, $bbcode->html),
$text);
break;
}
}
}
return $text;
}
Run Code Online (Sandbox Code Playgroud)
现在我的猜测是RegEx不喜欢模式中的递归.我怎样才能改进它?示例$ bbcode对象是这样的: …