实现代码:
<?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 >" }
相关文章
- ASP.NET自助建站系统中如何实现多语言支持? 2025-06-10
- 64M VPS建站:如何选择最适合的网站建设平台? 2025-06-10
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10