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
https://forums.phpfreaks.com/topic/121019-making-apostrophies-work/
Share on other sites

You can always convert the bbcode using that function, then run stripslashes() to the returned html.

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

 

Are there any other easier solutions out there?

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

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.