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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.