Home > Backend Development > PHP Tutorial > php addslashes uses recursion to use backslashes to quote strings_PHP tutorial

php addslashes uses recursion to use backslashes to quote strings_PHP tutorial

WBOY
Release: 2016-07-21 15:00:31
Original
781 people have browsed it

Implementation code:

Copy code The code is as follows:

function addslashes_deep($value)
{
//The most classic recursion in history, done in one line
return is_array($value) ? array_map('addslashes_deep', $value) : addslashes($value);
}

//Test data
$_POST['STR'] = "'fanglor ' is a boy >'";
$_GET['STR1'] = 'fanglor " is a boy >' ;

echo 'The current get_magic_quotes_gpc is '.get_magic_quotes_gpc();
echo "
";

//Determine whether get_magic_quotes_gpc is currently enabled
if (!get_magic_quotes_gpc()){
$_POST = addslashes_deep($_POST);
$_GET = addslashes_deep($_GET);
$_COOKIE = addslashes_deep($_COOKIE);
}

//Print results
var_dump ($_POST);
echo "
";
var_dump ($_GET);

?>


Print result:
The current get_magic_quotes_gpc is 0
array(1) { ["STR"]=> string(30) "'fanglor ' is \ a boy >'" }
array(1) { ["STR1"]=> string(26) "fanglor " is \ a boy >" }

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328076.htmlTechArticleImplementation code: Copy the code as follows: ?php function addslashes_deep($value) { //The most classic recursion in history , return is_array($value) ? array_map('addslashes_deep',...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template