BB Parser ~ PHP

Discussion in 'Web Design & Programming' started by Waffle, Dec 3, 2005.

Thread Status:
Not open for further replies.
  1. Waffle

    Waffle Alpha Geek

    Likes Received:
    38
    Trophy Points:
    0
    Ok I've developed a BB system similar to the one here, and many other sites, to allow bold etc to be used on forms etc etc.

    My code:

    PHP:

    <?php
    function bbcode($string){
    $r = array(
    "[b]" => "<b>",      // bold
    "[/b]" => "</b>",  
    "[i]" => "<i>",        //italic
    "[/i]" => "</i>"
    "[u]" => "<u>",    //underline
    "[/u]" => "</u>",
    "[br]" => "<br>",   //break
    );
    $string str_replace(array_keys($r), array_values($r), $string);

    echo 
    $string;
    }
    ?> 
    And I'd like to have more..ideally the following, but I have no idea how to code them.

    PHP:
    <?
    [
    url]www.site.com]Link Name[/url//I tried this, but it never worked properly. Also, the "Link Name" would have to be optional, in case it is missed out in user input - dont want any errors.

    [url=www.site.com]Site[/urlwould also be acceptable.

    [
    img][/img]
    [
    font color=red][/font]

    ?>
    suggestions?

    thanks.
     
  2. Waffle

    Waffle Alpha Geek

    Likes Received:
    38
    Trophy Points:
    0
    Right ignore that, I found what I was looking for.

    Thanks anyway.
     
Thread Status:
Not open for further replies.

Share This Page