Quick Question

Discussion in 'Programming' started by getatune, May 16, 2009.

  1. #1
    I am working on a little script & i want to save space on my server so I was wondering how can i make it so that when it gets the content off the mysql db it will change it from
    [url]http://google.com/[/url]
    HTML:
    to
    <a href="http://google.com">http://google.com</a>
    HTML:

     
    getatune, May 16, 2009 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    As Seller:
    100% - 3
    As Buyer:
    100% - 0
    #2
    you can do it with regular expressions or explode+str_replace
    if u cannot handle and have $$ for this contact me via pm
     
    crivion, May 16, 2009 IP
  3. James Barcellano

    James Barcellano Active Member

    Messages:
    114
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    
    function bbcode($content)
    {
    $content = preg_replace(”@\[b\](.+?)\[\/b\]@i”, “<b>$1</b>”, $content);
    $content = preg_replace(”@\[i\](.+?)\[\/i\]@i”, “<i>$1</i>”, $content);
    $content = preg_replace(”@\[u\](.+?)\[\/u\]@i”, “<u>$1</u>”, $content);
    $content = preg_replace(”@\[img\](.+?)\[\/img\]@i”, “<img src=\”$1\” alt=\”\” />”, $content);
    $content = preg_replace(”@\[url\](.+?)\[\/url\]@i”, “<a href=\”$1\”>[Link]</a>”, $content);
    $content = preg_replace(”@\[url=(.+?)\](.+?)\[\/url\]@i”, “<a href=\”$1\”>$2</a>”, $content);
    $content = str_replace(”\n”, ‘<br />’, $content);
    $content = preg_replace(”@\[code\](.+?)\[\/code\]@i", "<span class=\"box\">$1</span>", $content);
    return($content);
    }
    
    PHP:
    You can go to http://assasiner.wordpress.com/2006/11/23/bbcode-and-regex/ for more information.
     
    James Barcellano, May 16, 2009 IP