Jump to content

BBCode


lostprophetpunk

Recommended Posts

I am making a simple posting system.

 

I have the following code to deal with the bbcode...

function bbcode_format ($posted) {
        $posted = htmlentities($posted);

        $simple_search = array(
                                '/\[b\](.*?)\[\/b\]/is',                               
                                '/\[i\](.*?)\[\/i\]/is',                               
                                '/\[u\](.*?)\[\/u\]/is'
                                );

        $simple_replace = array(
                                '<b>$1</b>',
                                '<i>$1</i>',
                                '<u>$1</u>'
                                );

        // Do simple BBCode's
        $posted = preg_replace ($simple_search, $simple_replace, $posted);

        return $_POST['entry'];
}

The data of '$posted' is then inserted into the database. But when I view the post on a different page, it hasn't worked.

 

Am I doing something wrong?

Link to comment
https://forums.phpfreaks.com/topic/119937-bbcode/
Share on other sites

<?php

function bbcode_format($posted) {
        $posted = htmlentities($posted);

        $simple_search = array(
                                '/\[b\](.*?)\[\/b\]/is',                               
                                '/\[i\](.*?)\[\/i\]/is',                               
                                '/\[u\](.*?)\[\/u\]/is'
                                );

        $simple_replace = array(
                                '<b>$1</b>',
                                '<i>$1</i>',
                                '<u>$1</u>'
                                );

        // Do simple BBCode's
        $posted = preg_replace ($simple_search, $simple_replace, $posted);

        return $posted;
}

echo bbcode_format("[b][u][i]hello[/b][/u][/i]");
?>

Link to comment
https://forums.phpfreaks.com/topic/119937-bbcode/#findComment-617859
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.