PHP - Shorter Magic Quotes Solution

前端 未结 3 1879
终归单人心
终归单人心 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条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-22 05:29

    Solved it, I had to use the JSON_HEX_APOS flag in json_encode():

    if (get_magic_quotes_gpc() === 1)
    {
        $_GET = json_decode(stripslashes(json_encode($_GET, JSON_HEX_APOS)), true);
    }
    

    Before (mqgpc.php?name[got'cha]=O'Reilly):

    Array
    (
        [name] => Array
            (
                [got\'cha] => O\'Reilly
            )
    )
    

    After (mqgpc.php?name[got'cha]=O'Reilly):

    Array
    (
        [name] => Array
            (
                [got'cha] => O'Reilly
            )
    )
    

提交回复
热议问题