Home > php教程 > php手册 > body text

php addslashes 利用递归实现使用反斜线引用字符串

WBOY
Release: 2016-06-13 11:42:41
Original
1081 people have browsed it

实现代码:

复制代码 代码如下:


function addslashes_deep($value)
{
//史上最经典的递归,一行搞定
return is_array($value) ? array_map('addslashes_deep', $value) : addslashes($value);
}

//测试数据
$_POST['STR'] = "'fanglor ' is \ a  boy  >'";
$_GET['STR1'] = 'fanglor " is \ a  boy  >';

echo '当前get_magic_quotes_gpc为  '.get_magic_quotes_gpc();
echo "
";

//判断当前是否开启get_magic_quotes_gpc
if (!get_magic_quotes_gpc()){
$_POST = addslashes_deep($_POST);
$_GET = addslashes_deep($_GET);
$_COOKIE = addslashes_deep($_COOKIE);
}

//打印结果
var_dump ($_POST);
echo "
";
var_dump ($_GET);

?>


打印结果:
当前get_magic_quotes_gpc为 0
array(1) { ["STR"]=> string(30) "\'fanglor \' is \\ a boy >\'" }
array(1) { ["STR1"]=> string(26) "fanglor \" is \\ a boy >" }
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!