问题
preg_replace('/\[quote\=(.*?);(.*?)\](.*?)\[\/quote\]/ms', '<blockquote>Posted by: \1 at \2.<br/>\3</blockquote>', $text);
This is what I use to replace the [quote=user;id]content[/quote]
bbcode. Anyway, it works fine only, if there is one quote in post.
If I got:
[quote=user1;1] [quote=user0;0]some content here[/quote]
this is my reply to user0 post[/quote]
It'll replace only first quote, other will be just not replaced by the <blockquote>
.
How can I fix that?
回答1:
tested, repaired version
<?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
来源:https://stackoverflow.com/questions/7632325/bbcode-preg-replace-and-double-quotes