www.webdeveloper.com
Results 1 to 6 of 6

Thread: Reading all the URL parameters

  1. #1
    Join Date
    Feb 2006
    Posts
    21

    Reading all the URL parameters

    Hi, i wanted to know how i can read all the parameters coming from the URL in PHP. For example:

    www.something.com?a=1&b=2&c=3

    and then in a php file i have something like a cycle that gives me an output like this:

    First Parameter: a is 1
    Second Parameter: b is 2
    Third Parameter: c is 3

    Thanks for any help, hope i made myself clear!

  2. #2
    Join Date
    Dec 2005
    Posts
    2,984
    This is how you could do it. There's probably an easier way

    PHP Code:
    $keys = array();
    $values = array();

    foreach (
    $_GET as $key => $value) {
     
    array_push($keys$key);
     
    array_push($values$value); 
    }

    $variables  sizeof($keys);

    for(
    $i=0;$i<=($variables-1);$i++) {
     
    $number $i+1;
     echo 
    "Variable $number is: $keys[$i] is $values[$i]<br />";

    Last edited by aj_nsc; 02-14-2007 at 06:19 PM.

  3. #3
    Join Date
    Feb 2007
    Posts
    49
    A more universal example:

    PHP Code:
    foreach($_GET as $i => $k)
    echo 
    "Variable number ".($r++).": Key:$i Value:$k<br>\n"
    Or you could just use print_r:

    PHP Code:
    print_r($_GET); 
    Last edited by zackbloom; 02-14-2007 at 06:26 PM.

  4. #4
    Join Date
    Dec 2005
    Posts
    2,984
    see...

  5. #5
    Join Date
    Dec 2004
    Posts
    439
    PHP Code:
    while(list($key,$value) = each($_GET)){
    // do whatever you want in here


  6. #6
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    This is old school stuff.
    Quote Originally Posted by decibel
    PHP Code:
    while(list($key,$value) = each($_GET)){
    // do whatever you want in here

    Use the more efficient FOREACH proposed by ZackBloom.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles