PHP - BBCode 解析器 - 使用正则表达式和 preg_replace 递归 [quote] [英] PHP - BBCode parser - recursive [quote] with regex and preg_replace

查看:65
本文介绍了PHP - BBCode 解析器 - 使用正则表达式和 preg_replace 递归 [quote]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作自己的 bbcode 解析器,但在尝试进行递归引用时遇到了问题.

i'm making my own bbcode parser, and i've a problem when i try to do the recursive quote.

这是我的代码:

 function forumBBCode($str){
$format_search=array(
'#\[quote=(.*?)\](.*?)\[/quote\]#is'
);

$format_replace=array(
'<blockquote class="quotearea"><i><a class="lblackbu" href="./index.php?status=userview&userv=$1">$1</a> wrote :</i><br />$2</blockquote>'
);

$str=preg_replace($format_search, $format_replace, $str);
$str=nl2br($str);
return $str;
}

我必须添加/编辑什么才能进行递归引用?换句话说,当一个引号在另一个引号内时......

what i must add/edit to do a recursive quote? in other words, when a quote is inside another quote...

干杯和 tnx 的帮助

cheers and tnx for the help

推荐答案

参见此处:PHP 手册中的递归模式.

这也可能会让您感兴趣,尽管它更多的是技术性:为什么是递归正则表达式不是正则表达式?

This may also interest you, though it's more of a technicality: Why is recursive regex not regex?

这篇关于PHP - BBCode 解析器 - 使用正则表达式和 preg_replace 递归 [quote]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆