Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: BBcode help? :)

  1. #11
    Join Date
    Jan 2006
    Location
    Kent
    Posts
    987
    Tokens
    0

    Default

    Is there a way in which you could produce arrays for each of them, so that it only requires one preg_replace? I'm not asking you specifically to do it, but is there a way?
    This is our situation and we're happy to be here,
    I wouldn't change this place for anything.


  2. #12
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Quote Originally Posted by Joe! View Post
    Is there a way in which you could produce arrays for each of them, so that it only requires one preg_replace? I'm not asking you specifically to do it, but is there a way?
    PHP Code:
    <?php

    $string 
    '[b]hay [u]lol[/u][/b]';

    $bbcode = array(
                        
                        
    '/\[b\](.*?)\[\/b\]/is',
                        
    '/\[u\](.*?)\[\/u\]/is'
                        
                    
    );
                    
    $replace = array(
                    
                        
    '<strong>$1</strong>',
                        
    '<u>$1</u>'
                        
                    
    );
                    
    $string preg_replace$bbcode$replace$string );

    echo 
    $string;

    ?>

  3. #13
    Join Date
    Apr 2006
    Location
    London, England
    Posts
    696
    Tokens
    0

    Default

    @excellent do this:

    PHP Code:
    $whatever "[b] bold [/b] [i] italics [/i]";
    echo 
    bbcode($whatever); 
    EDIT: simon beat me
    Last edited by DUB; 26-09-2008 at 09:57 PM.
    ;veni vidi vici
    ;i came, i saw, i ownt

  4. #14
    Join Date
    Jan 2006
    Location
    Kent
    Posts
    987
    Tokens
    0

    Default

    Ah thankyou I know this may sound dumb, but how do you know where to use slashes and all that with the bbcode bit(/\[b\]) etc? Cheers
    This is our situation and we're happy to be here,
    I wouldn't change this place for anything.


  5. #15
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    If the character is used in reg ex, then you need to escape it.

  6. #16
    Join Date
    Jul 2004
    Location
    California
    Posts
    8,725
    Tokens
    3,989
    Habbo
    HotelUser

    Latest Awards:

    Default

    this worked for me when changing font, size or color using BB:
    PHP Code:
    $string preg_replace("(\[font=(.+?)\](.+?)\[\/font\])","<font face=$1>$2</font>",$string);
    $string preg_replace("(\[color=(.+?)\](.+?)\[\/color\])","<font color=$1>$2</font>",$string);
    $string preg_replace("(\[size=(.+?)\](.+?)\[\/size\])","<font size=$1>$2</font>",$string); 
    Last edited by HotelUser; 27-09-2008 at 02:09 PM.
    I'm not crazy, ask my toaster.

Page 2 of 2 FirstFirst 12

Posting Permissions

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