$_SERVER[] Help

Discussion in 'PHP' started by MajHate, May 10, 2009.

  1. #1
    Hello,

    I am trying to get some information from the url. Let's say I have:

    http://example.com/folder/test.php

    Is there a way where I can isolate "test" on its own? I've been looking at the $_SERVER variables but I cant find what I'm looking for. Any ideas?

    Thank You,
    Jason
     
    MajHate, May 10, 2009 IP
  2. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can you explain more... not sure what your asking ?

    Have a look here http://ie.php.net/manual/en/reserved.variables.server.php maybe you want $_SERVER['SCRIPT_FILENAME']

    or perhaps your looking for
    <?php
    $content = file_get_contents('http://example.com/folder/test.php');
    echo $content;
    ?>
    PHP:
     
    pixmania, May 10, 2009 IP
  3. MajHate

    MajHate Member

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    MajHate, May 10, 2009 IP
  4. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sorry I'm still not with you.. but that could be me...:) where do you want this "test" word to appear ?

    <a href="http://example.com/folder/test.php">test</a> will appear as test on a page
     
    pixmania, May 10, 2009 IP
  5. MajHate

    MajHate Member

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    MajHate, May 10, 2009 IP
  6. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Ok with you now...

    Try this
    <?php
    
    $url = $_SERVER['PHP_SELF'];
    
    $path = explode('/',$url);
    $pl = count($path);
    $directory = $path[$pl-2];
    
    $filename = explode('.',$path[$pl-1]);
    $word = $filename[0];
    
    echo $word;
    
    ?>
    
    PHP:
     
    pixmania, May 10, 2009 IP
  7. MajHate

    MajHate Member

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    Thank You!!!
     
    MajHate, May 10, 2009 IP
  8. bozy12v

    bozy12v Active Member

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #8
    $word = basename($_SERVER['SCRIPT_NAME'], '.php'); 
    Code (markup):
    That's the fast way to do that :D
     
    bozy12v, May 10, 2009 IP