我在一个用
PHP编写的网站上为自己的个人论坛编写了一个引用函数.
引用的标签看起来像[quote = username] message [/ quote],所以我写了这个函数:
$str=preg_replace('#\[quote=(.*?)\](.*?)\[/quote\]#is', '
', $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, '
');}
$str=preg_replace($format_search, $format_replace, $str);
只有在出现次数正确的情况下才能补充.所以它应该(对吧?)来防止html破坏或其他恶意攻击.你怎么看?