BBCode

Posted by Pete | Posted in PHP Functions | Posted on 16-07-2009-05-2008

0

Bulletin Board Code or BBCode is a lightweight markup language used to format posts in many message boards. Formats include [b]BOLD[/b] [i]Italics[/i] etc. We will show you how you can create your own function to accept BBCode and will show an example on how to use it.

 Value. The key is the item that will be typed e.g [b] the value will be the html equivilant.
     */
    $BBCode = array("&" => "&", "<" => "<", ">" => ">", "[b]" => "",
        "[/b]" => "", "[i]" => "", "[/i]" => "", "[u]" => "", "[/u]" =>
        "", "[img]" => ""); // Comment Above
    $parsedtext = str_replace(array_keys($BBCode), array_values($BBCode), $text); //This function will get the input string. and then the keys and values of the array above. It will then replace them with the html equivilant.
    return $parsedtext; // Return $parsedtext.
}
?>

To run this function you can use the following.

Write a comment

You must be logged in to post a comment.

Tutorials Written By Peter Kelly