首页 > Web开发 > 详细

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

时间:2016-01-16 09:01:16      阅读:127      评论:0      收藏:0      [点我收藏+]

实现代码:

复制代码 代码如下:

<?php
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 "<br/>";

//判断当前是否开启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 "<br/>";
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 >" }

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

原文:http://www.jb51.net/article/40308.htm

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!