|
本文介绍下,php利用递归实现使用反斜线引用字符串的方法,通过一个例子,帮助大家的理解。
php addslashes 递归反斜线引用字符串,代码如下:
<?php
//addslashes递归
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
//by bbs.it-home.org
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怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号