Extracting the file name with a name/value pair

Discussion in 'PHP' started by tintumon, Sep 10, 2010.

  1. #1
    I learned recently that I can use basename($_SERVER['SCRIPT_NAME']) to extract the current file name. I use it, with some other code, to offer better navigation links.

    I now need to modify my script so that I can extract the current file name and the info I'm passing through the URL. So, instead of extracting just myscript.php, I now need to identify myscript.php?info=general.

    Can you tell me how to modify basename($_SERVER['SCRIPT_NAME']) so that it also extracts the name/value pair that gets passed through the URL?

    Thank you for your time.
     
    tintumon, Sep 10, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    basename($_SERVER['REQUEST_URI']);  // just in case thats URi not URL :) 
    PHP:
    which gives you the myscript.php?info=general
     
    Last edited: Sep 10, 2010
    MyVodaFone, Sep 10, 2010 IP
  3. HungryMinds

    HungryMinds Active Member

    Messages:
    216
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    63
    #3
    Hi!
    Run This Query And Choose Your Server Variable Which U Want To Use.

    <?PHP

    foreach($_SERVER as $key_name => $key_value) {
    print $key_name . " = " . $key_value . "<br>";
    }

    ?>
     
    HungryMinds, Sep 10, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    You'd have to use the $_SERVER['REQUEST_URI'] variable instead - as previously suggested by MyVodaFone. You may also find useful the parse_str() function.
     
    danx10, Sep 10, 2010 IP
  5. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #5
    Try

    parse_url($_SERVER['REQUEST_URI']);
    PHP:
     
    Kaizoku, Sep 13, 2010 IP