Web Analytics Made Easy -
StatCounter Basic BB Code - CodingForum

Announcement

Collapse
No announcement yet.

Basic BB Code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Basic BB Code

    Could someone show me some basic examples to turn [b] into bold text and then [php] to highlighted code?

    I only need the [php] and the [b] for now and I think I could use those examples to do the rest.

    Thanks a million guys!
    - Stevie
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #3
    Thanks, after browsing some tutorials as well, I have came up with this.
    PHP Code:
    function parse_bb($str){
            
            
    $this->string $str;
        
            
    $search = array
            (
                
    '#\[B\](.+?)\[\/B]#is',
                
    '#\[I\](.+?)\[\/I]#is',
                
    '#\[U\](.+?)\[\/U]#is',
                
    '#\[COLOR=([a-z0-9\#+?)\](+.?)\[\/COLOR\]#mis',
            );
            
            
    $replace = array
            (
                
    '<strong>$1</strong>',
                
    '<em>$1</em>',
                
    '<span style="border-bottom: 1px solid;">$1</span>',
                
    '<span style="color: $1">$2</span>',
            );
            
            
    $this->parsed preg_replace($search,$replace,$this->string); /*LINE 474*/
        

    This is inside my class. Now, the [b] [i] and [u] works perfectly, but the [COLOR] does not work correctly. The error with it is
    Warning: Compilation failed: missing terminating ] for character class at offset 39 in c:\server\htdocs\blog\blog.php on line 476
    Could anyone see this error? Thanks.
    Last edited by SDP2006; Mar 1, 2004, 04:14 PM.
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

    Comment


    • #4
      Looks like vB parsed it, lol. I'll upload the code in a minute.

      EDIT

      Link in sig contains code. Very last function in class.
      Last edited by SDP2006; Mar 1, 2004, 04:14 PM.
      Stevie Peele
      Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
      #dev - any programming,etc. question
      #design - design discussion and critque
      #central - general chat
      Come join us!

      Comment


      • #5
        Without getting too deeply involved with the BB code, I think that

        Code:
         '#\[COLOR=([a-z0-9\#+?)\](+.?)\[\/COLOR\]#mis',
        should rather be

        Code:
         '#\[COLOR=([a-z0-9\#]+?)\](+.?)\[\/COLOR\]#mis',
        Note the additional square bracket after the hash sign in the middle.
        De gustibus non est disputandum.

        Comment


        • #6
          Thanks for your help, but that still gives me an error
          Warning: Compilation failed: nothing to repeat at offset 25 in c:\server\htdocs\blog\blog.php on line 476


          Thanks a ton, mordred.

          Stevie
          Stevie Peele
          Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
          #dev - any programming,etc. question
          #design - design discussion and critque
          #central - general chat
          Come join us!

          Comment


          • #7
            Yeah, I see it now too. The repetition in the middle makes no sense, since nothing's before the + sign. Give this repaired code a shot:

            Code:
            '#\[COLOR=([a-z0-9\#]+?)\](.+?)\[\/COLOR\]#mis',
            De gustibus non est disputandum.

            Comment


            • #8
              All right! Now we're getting somewhere!

              Thanks, I have a feeling I'll be back for more help. lol.

              Thanks
              Stevie Peele
              Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
              #dev - any programming,etc. question
              #design - design discussion and critque
              #central - general chat
              Come join us!

              Comment


              • #9
                Originally posted by SDP2006
                Thanks, I have a feeling I'll be back for more help. lol.
                You're welcome, and I have the same feeling as you.
                But don't let this sarcastic comment of me restrain you from asking further questions. If the code above is what you made after reading the tutorials you requested recently, that's quite impressive, honestly.
                De gustibus non est disputandum.

                Comment


                • #10
                  Okay, I lied.

                  I modified some of it. Anyways, im in trouble again.

                  http://www.net-riches.com/viewcode.php at the very bottom.

                  I'm wanting to PHP to be highlighted, can you elaborate?

                  Thanks
                  Stevie Peele
                  Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
                  #dev - any programming,etc. question
                  #design - design discussion and critque
                  #central - general chat
                  Come join us!

                  Comment


                  • #11
                    It's not one of the easiest tasks to perform, but you can try this quick hack and see if you can use it in your code. As to how it works, look up the "e" regex modifier in the manual, that's the main trick behind it. Another alternative would be to use preg_replace_callback(), but I'm tired right now to rewrite the code.

                    Code:
                    $str = 'foo [ php]
                    echo $str;
                    mysql_query($bla, $urgh);
                    [/ php] adsfa';
                    
                    //	use the highlight_string() function combined with the "e" modifiere
                    $str = preg_replace(
                    	'#\[PHP\](.+?)\[\/PHP]#ise', 
                    	"highlight_string('<?php /*foo*/ ' . '\\1' . '//foo?>', true)", 
                    	$str
                    );
                    
                    //	clean up redundant <?php PIs
                    $str = preg_replace('~(.+?foo\*/)|(//foo.+?$)~im', '', $str);
                    
                    echo $str;
                    Hopefully the slashes stay as they are meant to stay... vBulletin, behave this time!

                    Edit: There ares paces before the php in brackets to prevent vB code parsing...
                    De gustibus non est disputandum.

                    Comment


                    • #12
                      That uber lost me. Sorry could you edit this code to make it work? I'm kinda lost as to where to put things. Thanks a ton.

                      Thanks so much.
                      Attached Files
                      Stevie Peele
                      Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
                      #dev - any programming,etc. question
                      #design - design discussion and critque
                      #central - general chat
                      Come join us!

                      Comment


                      • #13
                        Mordred, my friend, wherfore art thou?

                        Stevie Peele
                        Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
                        #dev - any programming,etc. question
                        #design - design discussion and critque
                        #central - general chat
                        Come join us!

                        Comment


                        • #14
                          Don't worry, I'm still alive. You might take a look at the attached file.

                          EDIT: Argh, forgot the HTML code you wanted to surround the highlighted code with. Do you have to use font tags *shudder*?
                          Attached Files
                          Last edited by mordred; Mar 2, 2004, 05:47 PM.
                          De gustibus non est disputandum.

                          Comment


                          • #15
                            Thanks a ton. I'll have to test it when I get home
                            Stevie Peele
                            Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
                            #dev - any programming,etc. question
                            #design - design discussion and critque
                            #central - general chat
                            Come join us!

                            Comment

                            Working...
                            X