PHP - PDO return escaping slash, how to remove it?
I am doing some select with PDO object, but after fetch
result, I got string with escaped '
to 开发者_开发问答\'
, how can I disable that?
It seems like you might be having some trouble with Magic Quotes. You can disable them by following the instructions here. It's highly recommended that you disable them instead of sidestepping them by using a function to just strip the slashes out.
Looks like you have magic quotes turned on.
You should actually turn off the magic quotes from php.ini.
Or from within script, you can handle it like this:
if (get_magic_quotes_gpc())
{
$str = stripslashes($str);
}
Now you can use the $str
variable normally.
I was working on a shared-hosting that I didn't have access to php.ini
-- ini_set()
won't work also. This snippet worked like a charm: [source]
// since PHP 5
if (get_magic_quotes_gpc()) {
function stripslashes_gpc(&$value)
{
$value = stripslashes($value);
}
array_walk_recursive($_GET, 'stripslashes_gpc');
array_walk_recursive($_POST, 'stripslashes_gpc');
array_walk_recursive($_COOKIE, 'stripslashes_gpc');
array_walk_recursive($_REQUEST, 'stripslashes_gpc');
}
精彩评论