tags:

views:

75

answers:

4

Hi when I post something on my site and use quotations in it I get something like this

\"

What do I need to do to my code to fix this?

+3  A: 

It’s probably Magic Quotes that’s causing this behavior. Try to disable them or remove them with stripslashes.

Gumbo
Thanksphp_flag magic_quotes_gpc Off in the .htaccess file did fix it!
AskaGamer
You didn't think to google "php remove slashes"? It's the first link... it even mentions "magic quotes" in the PHP.net documentation. Everything is there at your fingertips...
Mark
Hi Mark, I enjoy using stackoverflow so I figure why not ask and continue to support SO.
AskaGamer
No - don't use stripslashes except as a LAST resort.Magic quotes are deprecated and have never worked properly. The right way to solve this is to remove the magic_quotes settings from the php.ini (and other places where these values can be set).C.
symcbean
+1  A: 

This is due to the PHP setting magic_quotes_gpc which is a mess to work with. You can use stripslashes to take away the slashes, but then the code won't work if the magic_quotes_gpc setting is off. Something like this will probably solve it for you:

<?php
$string = $_POST['msg'];
if(get_magic_quotes_gpc()) {
  $string = stripslashes($string);
}
?>

Or remove them altogether (this will work both with and without magic_quotes_gpc, good for the times when you can't change the server configuration):

<?php
if(get_magic_quotes_gpc()) {
  foreach(array('_POST', '_GET', '_COOKIE') as $gpc) {
    foreach($$gpc as $k => $v) {
      ${$gpc}[$k] = stripslashes($v);
    }
  }
}
?>
Emil Vikström
+1 For providing code :)
AntonioCS
A: 

You will need to use Stripslashes() to get it to output without them. Default about it is here

http://au.php.net/manual/en/function.stripslashes.php

kwhohasamullet
A: 

Be sure to check whether it is the Magic quotes using the value of magic_quotes_gpc(). Use stripslashes on all values and read something about XSS. stripslashes() alone is not enough security.

When outputting the form values, make sure to format them properly, check out htmlspecialchars(), mysql_real_escape_string() or, if you use PDO, the quote() function.

Ralf MC