0

i want to filter the url based on some parameters in it, separated by a plus (+).

This is a sample url:

http://localhost/a.php?f1=a+b+1&f2=c+d+2&f3=e+f+3&.............

Now i want to get each of the parameters in f1, f2, f3....... like i want to fetch the values of a, b, and 1 from parameter f1.

How can i go ahead with this...

2 Answers 2

2
$query = explode("&", $_SERVER['QUERY_STRING']);
$values = array();
foreach($query as $q){
    $vars = explode('=', $q);
    $values[$vars[0]] = explode('+', $vars[1]);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Gaurav, but it fetches the parameters of just f1, i want to fetch parameters of all, i.e., f1, f2, f3, ....
0

$f1 = $_GET['f1']; //Same for f2, f3, etc..

$values = explode('+', $f1);

$a = $values[0];

echo $a; //Would echo the first value of the f1 key up to the first +

3 Comments

It is ok, but first how do i fetch each of the parameters f1, f2, f3.... using any regular expression? There can be n number of f1, f2, f3...
I'm a little confused you don't need an reg exs for this. There can be unlimited number of values per one key. It can make it ugly but would work. You would simply do: $f2 = $_GET['f2']; $values = explode('+',$f2); $c = $values[0]; $d = $values[1];
Oh yeah you can just keep incrementing the get global variable for which ever specific key you want. It is unlimited.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.