6

i am retrieving the parameters using $_REQUEST. Is there a way of finding total no. of parameters in URL instead of retrieving each one and then counting ?

1
  • 2
    what abount count($_GET) count($_POST) or count($_REQUEST) isnt working for you? Commented Jan 18, 2013 at 11:43

4 Answers 4

7

This will give you the total number of & separated URL query parameters:

count(explode('&', $_SERVER['QUERY_STRING']))

If you only want unique parameters, use $_GET instead:

count($_GET)
Sign up to request clarification or add additional context in comments.

2 Comments

thanks. on the basis of your idea i used count($_REQUEST) that worked too.
4

Retrieve them with $_GET. This should be enough.

Example:

// url: index.php?a=1&b=2&c=3
echo count($_GET); // 3 params, $_GET['a'], $_GET['b'], $_GET['c']

Note: you can also pass arrays in url ( check here ), and the whole array is counted once.

1 Comment

Good catch on arrays. Deleting mine in your favor
0

This will do the trick for you. Try this :

$total = count($_GET);
echo $total;

Comments

0

If you only want the parameters in the URL, it's better to use $_GET. Since $_REQEUST contains the contents of $_GET, $_POST and $_COOKIE. see php.net

And if you want to know the number of parameters, you can get count the number of parameters that are in the URL using this: count($_GET).

Comments

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.