Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Posts
    131
    Thanks
    28
    Thanked 7 Times in 7 Posts

    Need help with regex / bbcodes

    Hello.

    I'm creating a quote-message function. I want to quote a message, and if another person quotes me, it adds all those extra quotes all-in-one.

    Quoting one message works - however, when there's more, the bbcode doesn't work.

    Example:
    PHP Code:
    [quote]User 1 said:
    [
    quote]User 2 said:
    Bla bla[/quote]
    True![/quote]
    Fail
    But when it's displayed, it only turns one pair of into a plain grey box with text, and the others remain as text "[ quote]" and "[/ quote]".

    I hope that made any sense.

    My BBcode script is as follows:
    PHP Code:
    <?php
    function bbcode($text){
        
    $find = array( 
        
    "'\[quote](.*?)\[/quote\]'is"
        
    ); 
        
        
    $replace = array( 
        
    "<div style=\"border: 1px solid #000000; background: #F2F2F2;\"><div style=\"padding: 3px;\">\\1</div></div>"
        
    ); 

        
    $text preg_replace($find,$replace,$text);
        return 
    $text;
    }
    ?>
    Also to mention, I'm not that great/familiar with regex yet.

  • #2
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,547
    Thanks
    57
    Thanked 148 Times in 147 Posts
    "'\[quote](.*?)\[/quote\]'is"
    <=
    "#\[quote\](.*?)\[quote\]#is"

    note: This will retrieve the first parent and all children quotes.
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #3
    Regular Coder
    Join Date
    Aug 2009
    Posts
    131
    Thanks
    28
    Thanked 7 Times in 7 Posts
    @Phil:

    Nothing happened. I also edited your last [ quote] to [ /quote]. But same result as before.

  • #4
    Regular Coder
    Join Date
    Aug 2009
    Posts
    131
    Thanks
    28
    Thanked 7 Times in 7 Posts
    Can anyone help? I still haven't figured it out.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •