PHP - Shorter Magic Quotes Solution

前端 未结 3 1880
终归单人心
终归单人心 2020-12-22 04:43

I\'m writing a app that needs to be portable. I know I should disable magic quotes on the PHP configuration but in this case I don\'t know if I can do that, so I\'m using th

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-22 05:44

    I usually solve that problem this way:

    function smagic($params){
        if(get_magic_quotes_gpc()){
            if(!is_array($params))
                return stripslashes($params);
            else
                return array_combine( array_map('stripslashes',array_keys($params)), array_map('smagic',array_values($params)) );
        }
    }
    

    And then, for $_GET:

    $_GET = smagic($_GET);
    

提交回复
热议问题