Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: BB Code?

  1. #1
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default BB Code?

    Ok, im wanting to do something with bb code..

    Would the PHP for it be like...
    PHP Code:
    <?php
     
    if(preg_match("[center]",$body) && preg_match("[/center]",$body))
    {
    preg_replace("[center]","<div align=\"center\">");
    preg_replace("[/center]","</div>");
    }
    ?>
    Last edited by MrCraig; 15-10-2007 at 10:55 AM.
    Coming and going...
    Highers are getting the better of me

  2. #2
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    You don't do it like that. It will slow down the script and you are calling uncessery functions. Also preg_replace returns a value and does not automatically update the source value.

    Example:

    PHP Code:
    $value preg_replace('#\[b\](.*?)\[/b\]#i','<strong>$1</strong>',$value); 

  3. #3
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    Ty =]

    Does anyone know what the PHP would be for
    PHP Code:
    [font=verdana][color=#006699]Hi There[/color][/font] 
    And what would the javascript be for inserting the tags into the textarea? (Called privmsg)
    Last edited by MrCraig; 16-10-2007 at 11:37 AM.
    Coming and going...
    Highers are getting the better of me

  4. #4
    Join Date
    Sep 2007
    Location
    USA
    Posts
    474
    Tokens
    0

    Default

    hmm well i would search
    PHP Font Attributes Tutorial

    however you may also find this HTML to bbCode Converter it also translates to other forum codes

    http://www.seabreezecomputers.com/html2bbcode/
    Post Meter
    ______________________________________________
    400 450 500 550 600 650 700 750 800 850 900-1k
    Green=Done | Orange=Almost | Red=Not Done
    ______________________________________________
    Habbo fury Coming Soon!
    My Img tag has ran away

  5. #5
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    Erm.. I dont need to know how to translate forum codes..
    Coming and going...
    Highers are getting the better of me

  6. #6
    Join Date
    Jul 2007
    Location
    Scotland
    Posts
    529
    Tokens
    0

    Default

    Use str_replace

    Eg:

    PHP Code:
    $string str_replace("[font=""<font="$string); 

  7. #7
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    Bad idea because you can get unclosed tags.

    Quote Originally Posted by RichardKnox View Post
    Use str_replace

    Eg:

    PHP Code:
    $string str_replace("[font=""<font="$string); 

  8. #8
    Join Date
    Apr 2006
    Location
    Salford
    Posts
    2,108
    Tokens
    0

    Latest Awards:

    Default

    On your page have

    PHP Code:
    <?php
    session_start
    ();
    include_once 
    "FILENAMEHERE.php"?>
    Then in FILENAMEHERE.php..

    PHP Code:
    <?
    function replace($txt) {
    $txt str_replace(":D""HTML Here"$txt);
    $txt str_replace("BB Code Here";
    }
    ?>
    And it you want to add two or three

    PHP Code:
    <?
    function replace($txt) {
    $txt str_replace(":D""HTML Here"$txt);
    $txt str_replace("BB Code Here"$txt str_replace(":D""HTML Here"$txt);
     
    $txt str_replace("BB Code Here";
    }
    ?>

  9. #9
    Join Date
    Jan 2007
    Location
    Canada eh?
    Posts
    766
    Tokens
    75

    Default

    Well personally I would just use an array....
    PHP Code:
    <?php
    $find 
    = array('[u]''[/u]''[b]''[/b]');
    $rep = array('<u>''</u>''<b>', </b>');
    $replace = str_replace($find, $replace);
    ?>

  10. #10
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    I would highly recommend you don't do any of the above and stick with regular expressions using preg_replace. If you want to use arrays, preg_replace also supports indexed arrays.

Page 1 of 2 12 LastLast

Posting Permissions

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