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
    New Coder
    Join Date
    Apr 2004
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    regular expression for [quote] bbcode

    So far i have
    Code:
    $str = eregi_replace('\[quote=([^]]+)\]([^\[]+)\[/quote\]', '<b>\\1 says:</b> <br /><table cellspacing="0" cellpadding="3" style="border: 1 solid; border-color: #cccccc; background-color: #ffffff;"><tr><td>\\2</td></tr></table>', $str);
    this works if you are quoting someone who hasn't quoted someone in their message.
    If i wanted to quote someone who already used the [quote] tag in their message, it doesn't do it right.
    What i was hoping to do with the regular expression is instead of this line
    ([^\[]+)
    which is take any character OTHER than left bracket [
    i want it to say take any character OTHER than [quote
    but i don't know how to do this
    obviously i have tried
    ([^\[quote]+)
    that doesn't work
    i don't know regular expressions very well, can anyone inform me?

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmm. i didn't realy took a close look at the regex, but i would simply run the eregi_replace() a few times. Like
    PHP Code:
    $original='YOUR INITIAL STRING GOES HERE';
    for(
    $i=0$i<=100$i++){   //assuming you'll have at most 100 levels of nested quotes 
       
    $str=eregi_replace(...,$original);
       if (
    $str==$original){
          break;  
    // so the loop is exited if no replaces have been made
       
    } else {
         
    $original $str;   //so the replace will be repeated on the result of this replace
       
    }

    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    New Coder
    Join Date
    Apr 2004
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey thanks!
    didn't even think to do it that way :-)
    thanks

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're welcome.

    It's a little usefull hack which keeps it all simple without a lott of extra overhead. Might even be the only sollution for your particular question.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

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