lostprophetpunk Posted August 23, 2008 Share Posted August 23, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/121019-making-apostrophies-work/ Share on other sites More sharing options...
Fadion Posted August 23, 2008 Share Posted August 23, 2008 You can always convert the bbcode using that function, then run stripslashes() to the returned html. Quote Link to comment https://forums.phpfreaks.com/topic/121019-making-apostrophies-work/#findComment-623858 Share on other sites More sharing options...
ignace Posted August 23, 2008 Share Posted August 23, 2008 set_magic_quotes_runtime(0); this turns off the auto slashes, however you will now have to manually add slashes using addslashes() Quote Link to comment https://forums.phpfreaks.com/topic/121019-making-apostrophies-work/#findComment-623859 Share on other sites More sharing options...
lostprophetpunk Posted August 23, 2008 Author Share Posted August 23, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/121019-making-apostrophies-work/#findComment-623906 Share on other sites More sharing options...
Lamez Posted August 23, 2008 Share Posted August 23, 2008 <?php $posted = str_replace("\\", "", $posted); ?> That will do it, I used it for my HTML thing! Quote Link to comment https://forums.phpfreaks.com/topic/121019-making-apostrophies-work/#findComment-623907 Share on other sites More sharing options...
Fadion Posted August 23, 2008 Share Posted August 23, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/121019-making-apostrophies-work/#findComment-623955 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.