How to remove \ before quotes in a input form
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 th开发者_JS百科is?
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
http://au.php.net/manual/en/function.stripslashes.php
精彩评论