Get URL query string parameters

前端 未结 11 1434
长情又很酷
长情又很酷 2020-11-22 17:41

What is the \"less code needed\" way to get parameters from a URL query string which is formatted like the following?

www.mysite.com/category/subcateg

11条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 17:57

    This code and notation is not mine. Evan K solves a multi value same name query with a custom function ;) is taken from:

    http://php.net/manual/en/function.parse-str.php#76792 Credits go to Evan K.

    It bears mentioning that the parse_str builtin does NOT process a query string in the CGI standard way, when it comes to duplicate fields. If multiple fields of the same name exist in a query string, every other web processing language would read them into an array, but PHP silently overwrites them:

     '3');
    ?>
    

    Instead, PHP uses a non-standards compliant practice of including brackets in fieldnames to achieve the same effect.

     array('1', '2', '3') );
    ?>
    

    This can be confusing for anyone who's used to the CGI standard, so keep it in mind. As an alternative, I use a "proper" querystring parser function:

    
    

提交回复
热议问题