Home > Article > Backend Development > Application examples of stripslashes and addslashes in php_PHP tutorial
First test whether magic_quotes_gpc is ON. If so, use array_map() to recursively restore the escaped data. Whether the automatic addslashes function is turned on, we can check it by checking it in php.ini or use the get_magic_quotes_gpc() function.
<?php // 说明: 用 stripslashes 还原 addslashes 转义后的数据 if(get_magic_quotes_gpc()) { function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : (isset($value) ? stripslashes($value) : null); return $value; } $_POST = stripslashes_deep($_POST); $_GET = stripslashes_deep($_GET); $_COOKIE = stripslashes_deep($_COOKIE); } ?>