[PHP]Sharing BBCode Function

Results 1 to 3 of 3
  1. #1
    Valued Member LegacyCode is offline
    MemberRank
    Aug 2009 Join Date
    HyruleLocation
    129Posts

    [PHP]Sharing BBCode Function

    I made this bbcode function in my spare time.
    Wanted to share it because i have no real use for it

    Info
    - Handles Nested Tags.
    - Contains Default Tags + Some extra
    - NO SECURITY ADDED!!!(Don't use this function without the proper security or else your site will get owned)

    I also added my own tag called m2i (mail to image)
    it will convert a mail address to a image to prevent spiders, scanners, crawlers or whatever you want to call them from reading them.

    also note its not properly tested if you find any erros/bugs
    don't come complaining it doesn't work.

    Ive seen others talk about bbcode before in php on ragezone
    so i hope someone has a use for it because i don't.

    PHP Code:
    <?
    # ---------------------------------------- #
    # -- BBCode Function Made by LegacyCode -- #
    # --- LegacyCode(Anti-Spam)hotmail.com --- #
    # -----------------------------------------#

    function bbcode($str) {
      function 
    tagmatch($tag,$prm,$inner) {
          switch (
    $tag) {
            
              
    // Bold 
              
    case 'b'
                  
    $rpl '<b>'.$inner.'</b>'
                  break;
                  
              
    // Underline    
              
    case 'u':
                  
    $rpl '<u>'.$inner.'</u>'
                  break;
                  
              
    // Italic  
              
    case 'i':
                  
    $rpl '<i>'.$inner.'</i>'
                  break;
              
              
    // Move
              
    case 'm':
                  
    $rpl '<marquee>'.$inner.'</marquee>'
                  break;
                  
              
    // Right
              
    case 'right':
                  
    $rpl '<div align="right">'.$inner.'</div>'
                  break;   
                  
              
    // Center 
              
    case 'center':
                  
    $rpl '<div align="center">'.$inner.'</div>'
                  break;
                  
              
    // Left
              
    case 'left':
                  
    $rpl '<div align="left">'.$inner.'</div>'
                  break; 
      
              
    // color
              
    case 'color':
                  
    $rpl '<span style="color: '.$prm.';">'.$inner.'</span>'
                  break;
                  
              
    // Mail to Image
              
    case 'm2i':
                  
    $rpl '<img src="m2i.php?mail='.$inner.'" />'
                  break;
                  
              
    // Image
              
    case 'm2i':
                  
    $rpl '<img src="'.$inner.'" />'
                  break;
                  
              
    // Pre
              
    case 'm2i':
                  
    $rpl '<pre>'.$inner.'</pre>'
                  break;     
              
              
    // Mail
              
    case 'mail':
                  if(
    $prm != '') {
                    
    $rpl '<a href="mailto:'.$prm.'">'.$inner.'</a>';
                  }
                  else {
                      
    $rpl '<a href="mailto:'.$inn.'">'.$inn.'</a>';
                  } 
                  break;
                  
              
    // Url
              
    case 'url':
                  if(
    $prm != '') {
                    
    $rpl '<a href="'.$prm.'">'.$inn.'</a>';
                  }
                  else {
                      
    $rpl '<a href="'.$inn.'">'.$inn.'</a>';
                  } 
                  break;
              
              
    // Video
              
    case 'video':
                  switch (
    $prm) {
                      case 
    'youtube':
                          
    $rpl '<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/MdXkGXD7gDc&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'.$inn.'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>';
                          break;
                    case 
    'google':
                          
    $rpl '<embed id=VideoPlayback src=http://video.google.nl/googleplayer.swf?docid='.$inn.'&hl=en&fs=true style=width:400px;height:326px allowFullScreen=true allowScriptAccess=always type=application/x-shockwave-flash> </embed>';
                          break;
                    case 
    'megavideo':
                          
    $rpl '<object width="640" height="480"><param name="movie" value="http://www.megavideo.com/v/'.$inn.'"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.megavideo.com/v/'.$inn.'" type="application/x-shockwave-flash" allowfullscreen="true" width="640" height="480"></embed></object>';
                        break;
                    case 
    'myspace':
                          
    $rpl '<a href="http://vids.myspace.com/index.cfm?fuseaction=vids.individual&videoid='.$inn.'">Waylon - Wicked Way Official Video</a><br/><object width="425px" height="360px" ><param name="allowFullScreen" value="true"/><param name="wmode" value="transparent"/><param name="movie" value="http://mediaservices.myspace.com/services/media/embed.aspx/m='.$inn.',t=1,mt=video"/><embed src="http://mediaservices.myspace.com/services/media/embed.aspx/m='.$inn.',t=1,mt=video" width="425" height="360" allowFullScreen="true" type="application/x-shockwave-flash" wmode="transparent"></embed></object>';
                        break;
                    case 
    'liveleak':
                          
    $rpl '<object width="450" height="370"><param name="movie" value="http://www.liveleak.com/e/'.$inn.'"></param><param name="wmode" value="transparent"></param><embed src="http://www.liveleak.com/e/'.$inn.'" type="application/x-shockwave-flash" wmode="transparent" width="450" height="370"></embed></object>';
                        break;             
                  }
                  break;
            
            
    // Quote
            
    case 'quote':
                
    $rpl '<blockquote>Quote : '.$prm.'<div style="border: 1px solid #000000;">'.$inn.'</div></blockquote>';       
                      
                    
    // Code
            
    case 'quote':
                
    $rpl '<blockquote>Code :<div style="border: 1px solid #000000;font-family:monospace;">'.$inn.'</div></blockquote>';
          
          }
          return(
    $rpl);
      }
      
      
    preg_match_all('/\[(.+?)(?:=(.+?))?\](.+?)\[\/\1\]/is',$str,$match);
      
    $sz sizeof($match[0]);
      for(
    $i=0;$i<=$sz;$i++) {
          
    $rpl[0] = tagmatch($match[1][$i],$match[2][$i],$match[3][$i]);
          do {
            if(
    preg_match('/\[(.+?)(?:=(.+?))?\](.+?)\[\/\1\]/is',$rpl[0],$submatch)) {
              
    $rpl[1] = tagmatch($submatch[1],$submatch[2],$submatch[3]);
              
    $rpl[0] = str_replace($submatch[0],$rpl[1],$rpl[0]);
            }
            else {
              break;
            }
          } while(
    1);
          
    $str str_replace($match[0][$i],$rpl[0],$str);
      }
      return(
    $str);
    }
    ?>
    PHP Code:
    <?php
    # ---------------------------------------- #
    # --- Mail to Image Made by LegacyCode --- #
    # --- LegacyCode(Anti-Spam)hotmail.com --- #
    # -----------------------------------------#

    header("Content-type: image/png");
    $str $_GET['mail'];
        
    $ftype 4;
    $width = (imagefontwidth($ftype)*strlen($str)+20);
    $hight = (imagefontheight($ftype)+10);
        
    $m2i imagecreate($width,$hight);
        
    $color = array('Background' => imagecolorallocate($m2i,2001090),
                   
    'Text' => imagecolorallocate($m2i,0,0,0));
                   
    imagestring($m2i,$ftype,10,5,$str,$color['Text']);
    imagepng($m2i);
    imagedestroy($m2i);
    ?>
    Last edited by LegacyCode; 15-09-09 at 08:10 AM.


  2. #2
    (oO (||||) (||||) Oo) jM2.me is offline
    MemberRank
    Aug 2009 Join Date
    USA (Fuck Yeah)Location
    2,527Posts

    Re: [PHP]Sharing BBCode Function

    Thats hecka nice.

    Thanks

  3. #3
    Proficient Member shadowmage121 is offline
    MemberRank
    Mar 2007 Join Date
    USALocation
    194Posts

    Re: [PHP]Sharing BBCode Function

    Very nice, looks like it's very neat to me. One of people's peeves is code that isn't indented etc. x]



Advertisement