Jump to content

Preg_replace switch around...


lostprophetpunk

Recommended Posts

I am working on an edit script for my article system, however I have come across a problem.

 

This code is for my posting script so that the bbcode is converted to html...

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

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

        $simple_replace = array(
                                '<b>$1</b>',
                                '<i>$1</i>',
                                '<u>$1</u>',
                                '<a href="$1" target="_blank">$2</a>',
                                '<br />',
                                '<img src="$1" alt="$2" />'
                                );

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

        return $posted;
    };

 

I would like to make it so that the function converts the html into the bbcode so that it can be edited.

Link to comment
https://forums.phpfreaks.com/topic/120374-preg_replace-switch-around/
Share on other sites

I'm assuming this is being used for a forum or messaging system.

 

You would not need a function to convert it. You would grab whatever was posted or messaged using $_POST['message'] and you can use it how it is. Before using the BB code function.

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.