Home  >  Article  >  Backend Development  >  Application examples of stripslashes and addslashes in php_PHP tutorial

Application examples of stripslashes and addslashes in php_PHP tutorial

PHP中文网
PHP中文网Original
2016-07-20 11:03:101233browse

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(&#39;stripslashes_deep&#39;, $value) : (isset($value) ? stripslashes($value) : null);
        return $value;
    }
 
    $_POST = stripslashes_deep($_POST);
    $_GET = stripslashes_deep($_GET);
    $_COOKIE = stripslashes_deep($_COOKIE);
}
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn