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?
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?
It’s probably Magic Quotes that’s causing this behavior. Try to disable them or remove them with stripslashes
.
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);
}
}
}
?>
You will need to use Stripslashes() to get it to output without them. Default about it is here
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.