本文介绍下,php利用递归实现使用反斜线引用字符串的方法,通过一个例子,帮助大家的理解。
php addslashes 递归反斜线引用字符串,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <?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/>" ;
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 );
?>
|
Copier après la connexion
打印结果:
当前get_magic_quotes_gpc为 0
array(1) { ["STR"]=> string(30) "\'fanglor \' is \\ a boy >\'" }
array(1) { ["STR1"]=> string(26) "fanglor \" is \\ a boy >" } |