There isn't necessarily a direct inverse of the quote
function (assuming PDO::quote
here). It surrounds the value by quotes and escapes special characters inside the string to form a valid SQL string literal according to the underlying driver of the database. And that may vary a bit from database to database and the specifics of your connection. You should also never need to unquote a string, because you're not supposed to use the quoted string in any other place but an SQL query:
sprintf('SELECT ... WHERE foo = %s', $pdo->quote($value))
There's no reason whatsoever to quote the value, and then unquote it again to use it anywhere else but an SQL query. Just use the original $value
instead of the quoted value. And of course, you should be using prepared statements with bound parameters instead of manual quoting to begin with, so you should hardly have any reason to touch this function ever.
Having said that, this should cover most cases, though is far from guaranteed to always produce the correct result:
$unquoted = stripslashes(substr($quoted, 1, -1));