BBCODE, preg_replace and double quotes

杀马特。学长 韩版系。学妹 提交于 2019-12-25 06:44:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!