【问题标题】:BBCODE, preg_replace and double quotesBBCODE、preg_replace 和双引号
【发布时间】:2011-11-29 17:54:25
【问题描述】:
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]

它只会替换第一个引号,其他不会被&lt;blockquote&gt;替换。

我该如何解决这个问题?

【问题讨论】:

    标签: php regex preg-replace bbcode quote


    【解决方案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

    【讨论】:

    • 谢谢,我马上试试。
    • 当我使用它时,我收到一条错误消息:Fatal error: Maximum execution time of 30 seconds exceeded in /home/public_html/[...]
    • 其实我也不知道是与否。您可以在 html、css、php 中尝试各种有效/无效的 BBCode,然后测试每个特殊字符是否有效。也取决于你的想法safe
    • 安全我的意思是,如果它不会“滞后”服务器,以防万一有很多报价。
    猜你喜欢
    • 2013-11-26
    • 2014-01-13
    • 2012-04-01
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-21
    相关资源
    最近更新 更多