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;
    }
原文地址:https://www.cnblogs.com/-mrl/p/13871550.html