php 递归引用,php – 论坛中的递归引用

我在一个用

PHP编写的网站上为自己的个人论坛编写了一个引用函数.

引用的标签看起来像[quote = username] message [/ quote],所以我写了这个函数:

$str=preg_replace('#\[quote=(.*?)\](.*?)\[/quote\]#is', '

$1 wrote :$2
', $str);

如果引用是一个,但是当用户引用引用时,这个不起作用,这不起作用.所以我需要一种递归引用来应用这种行为.

我试图搜索很多主题,但我真的不明白它是如何工作的.

将不胜感激任何有关此类操作的建议/提示!让我知道,谢谢!

编辑

最后,这是我自己的解决方案:

if(preg_match_all('#\[quote=(.*?)\](.*?)#is', $str, $matches)==preg_match_all('#\[/quote\]#is', $str, $matches)) {

array_push($format_search, '#\[quote=(.*?)\](.*?)#is');

array_push($format_search, '#\[/quote\]#is');

array_push($format_replace, '

$1 wrote :
$2');

array_push($format_replace, '

');

}

$str=preg_replace($format_search, $format_replace, $str);

只有在出现次数正确的情况下才能补充.所以它应该(对吧?)来防止html破坏或其他恶意攻击.你怎么看?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值