Jump to content

Making apostrophies work


lostprophetpunk

Recommended Posts

I am doing a blog system in PHP.

 

The thing that is annoying me the most is that the ' in words like "don't" doesn't work. It always displays \' rather than just '.

 

I have tried using stripslashes() but then that screws up my bbcode system (code below) and then that doesn't work. I have also tried htmlspecialchars() but then that makes the html of the bbcode not work at all.

 

    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;
    };

    $posted = bbcode_format($posted);

 

I just want a solution to this, so that I can still keep my bbcode.

Link to comment
Share on other sites

If you read my post, you would have picked up that I used that already and it failed.

 

My idea was to convert the bbcode first, then escape characters, as you didn't want to break the bbcode conversion. Anyway, as your data most surely comes from a textarea and not a database (which would mean you manually escaped), the scenario is very probable to have magic quotes turned on (as suggested by ignace). Turn them off as they are deprecated and removed from php6. In your php.ini:

 

magic_quotes = Off

magic_quotes_runtime = Off

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.