php 把cli控制台argv参数转化为标准的$_request变量

php index.php "/test/?a=1&b=2&c=3"

public static function argv_to_request()
    {
        if ($_SERVER['argv'] && count($_SERVER['argv']) > 1) {
            $str = $_SERVER['argv'][1];
            if (stripos($str, '?') !== false) {
                $arr = explode('?', $str);
                if ($arr && count($arr)) {
                    $_REQUEST['s'] = $arr[0];
                    parse_str($arr[1], $tmp);
                    if ($tmp && count($tmp)) {
                        $_REQUEST = array_merge($_REQUEST, $tmp);
                    }
                }
            } else {
                $_REQUEST['s'] = $str;
            }
            $_SERVER['REQUEST_URI'] = $str;
            $_SERVER['QUERY_STRING'] = 's='.$str;
        }

        return $_REQUEST;
    }

 

posted @ 2020-10-24 23:14  一个人的孤独自白  阅读(218)  评论(0编辑  收藏  举报