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 12 of 12
  1. #1
    New Coder
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    91
    Thanks
    21
    Thanked 0 Times in 0 Posts

    BBcode Parsing - Small Problem with [code][/code]

    Hey peepz,

    I've got a small problem with the following:

    Code:
        $bbcode = array(
            "'\[code\](.*?)\[/code\]'"
    
        $html = array(
    	"<div class=\"codetop\">CODE</div><div class=\"codemain\"><br /><br />\\1<br /><br /></div></div>"
    I've left all other BBcode out and smiley stuff, and other PHP code. I'm using the above (using code example from IPB forums) to replace [*code] with <div class= etc. It works, when the actual [*code] is on one line. If I have more text in the code, it doesn't work, example:

    Code:
    [*code]Blabla here [*/code]
    The above works fine. But when it has more text like below:

    Code:
    [*code]Blabla here
    And some more blabla here
    And then another bla here,
    Last but not least, one more bla[*/code]
    It doesn't work. Any idea how this can be resolved?
    Thank you for your time to read my post

  • #2
    New Coder
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    91
    Thanks
    21
    Thanked 0 Times in 0 Posts
    Nobody can help?
    Thank you for your time to read my post

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    What do you mean doesn't work? Doesn't show the code? Shows the code on one line, even though there's linebreaks in there?

  • #4
    New Coder
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    91
    Thanks
    21
    Thanked 0 Times in 0 Posts
    I'm going to post an image of what I mean:



    I've just inserted something into the database, using the bbcode sample parser I posted above. As you can see, it works, but when I posted stuff between the code tags which is more than one line, it doesn't.
    Thank you for your time to read my post

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Try something like this:
    PHP Code:
    <?php
    $str 
    '[code]blah blah
    blahblah


    blah[/code]'
    ;
    $bbcode = array('/\[code\](.*)\[\/code\]/s');
    $html = array('<div class="codetop">CODE</div><div class="codemain"><br /><br />\\1<br /><br /></div></div>');
    echo 
    '<pre>' preg_replace($bbcode$html$str) . '</pre>';
    ?>

  • #6
    New Coder
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    91
    Thanks
    21
    Thanked 0 Times in 0 Posts
    Nope, this also doesn't work. Isn't there a more easy way of solving this?
    Thank you for your time to read my post

  • #7
    New Coder
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    91
    Thanks
    21
    Thanked 0 Times in 0 Posts
    Nobody?
    Thank you for your time to read my post

  • #8
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    dev.bbcode.org

  • #9
    New Coder
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    91
    Thanks
    21
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by the-dream View Post
    dev.bbcode.org
    Doesn't exist.
    Thank you for your time to read my post

  • #10
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Add "s" to the end of the regex.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #11
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    http://www.tutorio.com/tutorial/simp...code-with-php/
    this gives you a pretty decent idea on how to make your own!
    Quote Originally Posted by HOTSCRIPTS.COM

    Description: A simple and effective script that allows you to implement bbcode type behaviour on your php website. You can redefine any of the BBCode elements with the built-in CSS Styles.
    for this file
    http://duncan.xtreme.net.nz/bbCode.php.txt
    hope this helps

  • #12
    New Coder
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    91
    Thanks
    21
    Thanked 0 Times in 0 Posts
    I believe this is what I needed!

    Something like this should work, although I have not tried it out yet. Thanks all for the replies and the help. If it worked I'll post my results here.
    Thank you for your time to read my post


  •  

    Posting Permissions

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