0
preg_replace('/\[quote\=(.*?);(.*?)\](.*?)\[\/quote\]/ms', '<blockquote>Posted by: \1 at \2.<br/>\3</blockquote>', $text);

这是我用来替换[quote=user;id]content[/quote]bbcode的。无论如何,只有在帖子中有一个报价时,它才能正常工作。

如果我得到:

[quote=user1;1] [quote=user0;0]some content here[/quote]

this is my reply to user0 post[/quote]

它只会替换第一个引号,其他不会被替换<blockquote>

我该如何解决?

4

1 回答 1

1

测试,修复版本

<?php
$out = '[quote=user1;1] [quote=user0;0]some content here[/quote]this is my reply to user0 post[/quote]';
$cnt = 1;
while($cnt != 0){
    $out = preg_replace('/\[quote\=(.*?);(.*?)\](.*?)\[\/quote\]/ms', '<blockquote>Posted by: \1 at \2.<br/>\3</blockquote>', $out, -1, $cnt);
}
echo $out;

http://codepad.org/3PoxBeQ5

于 2011-10-03T09:31:21.510 回答