PHP使用GET []从URL获取值[关闭]

I am trying to develop products filters for an online store I am working on. An example of what I mean is http://www.riverisland.com/men/just-arrived. I have managed to get a JavaScript to populate the URL when the sizes are clicked on but failed to get them remove value from URL when unchecked.

My main question here is this. Assuming I have my URL as:

http://127.0.0.1/shop/dresses/?s=1&s=2&s=3

How do I get my PHP to extract the values from the URL? How do I format a SQL query to search the values gotten from the URL using any sample query?

An easier solution is this.

Format your URL like http://127.0.0.1/shop/dresses/?s=1,2,3 as suggested by @Andrey.Popov. Then do the below.

if(isset($_GET['s']) && !empty($_GET['s']))
{
    $e = sanitizeFunction($_GET['s']);
    $d=explode(',',$e);
}

$d now has all your $_GET['s'] values.

That's the easier way I have figured out and it works!

In order to benefit from $_GET and other superglobals you have to follow the rules explained at Variables From External Sources. Since you've chosen to have several parameters with the same name and they do not contain properly paired square brackets you're basically on your own. The manual steps you must reproduce include:

  1. Extract the raw query string from $_SERVER['QUERY_STRING'], e.g.:

    $query_string = filter_input(INPUT_SERVER, 'QUERY_STRING');
    
  2. Parse out the string. As far as I know, there aren't built-in functions that do exactly this so I'd either google for a good third-party library or write a simple parser with regular expressions or good old explode().

  3. Decode the URL-encoded values with urldecode()