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 8 of 8

Thread: BBCode

  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts

    BBCode

    Hi,

    Does somebody has a BBCode function for me?

    And then i mean, not for 1 code, but for a few.

    Like:
    PHP Code:
    $string "[quote=Wanna][quote]Testing[/quote][b][i][Nice text[/i][/b][i][/i][/quote]"
    And that it excecute all the bbcode

    And also like this site, that text inside a php/code tag won't be transformed
    Hope you can help me with this.
    Last edited by Wanna; 09-14-2011 at 10:28 AM.

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    This forum isn't for us to give you code, it's to aid your learning and give you advice to solve problems.

    However, I will give you some example logic. You want to set up a set of rules, i.e. for this do this, and set up a preg_replace or str_replace to replace segments with your desired rule. It might be easier if you use recursion for this as well.

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    How could i make a recursion for the rule in the first rule then?
    Checking howmuch tags there's in a rule, and then loop that many trough a function?

  • #4
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    I think you're misunderstanding the concept of recursion. I'm not sure you even need it tbh. I'm sure you could define two arrays, one with patterns to find and one with patterns to replace with. Then, use preg_replace once to replace all your bbcode with your rules.

    Would have to get confirmation on how that works though. I've seen it done similar to that, but not entirely confident on it as I hardly ever use preg_replace.

  • #5
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    If workerd with preg_match before, and kind of created this already once.
    But only the quote workerd for the first time, and not the quote inside quote would be quoted :P

  • #6
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Maybe that's where recursion comes in, with some sort of combination of preg_match to make sure you catch the stragglers :P

  • #7
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    I think i got it now
    Thanks

  • #8
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    No problem


  •  

    Posting Permissions

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