Home » Php » PHP – PDO return escaping slash, how to remove it?

PHP – PDO return escaping slash, how to remove it?

Posted by: admin July 12, 2020 Leave a comment


I am doing some select with PDO object, but after fetch result, I got string with escaped ' to \', how can I disable that?

How to&Answers:

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.iniini_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');