Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2008
    Posts
    103
    Thanks
    1
    Thanked 8 Times in 8 Posts

    Getting the current pages url

    This is fairly simple based on what I hear, However I need to know if its possible to do that and get only the page your on without the file extension...

    ex)
    http://demo.com/randomdir/part_i_need.notthis

    if this is possible to just get that part can somebody show me an example?


    THANKS,
    ~p4plus2~

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Mar 2008
    Posts
    103
    Thanks
    1
    Thanked 8 Times in 8 Posts
    Thanks for the help!

    for anybody who needs a similar code here it is:

    PHP Code:
    <?php
    $path 
    $_SERVER['REQUEST_URI'];
    $extension '.php';
    $file basename($path$extension);
    echo(
    "$file");
    ?>
    Or a more practical use(which is similar to how I am using it):

    PHP Code:
    <?php
    $path 
    $_SERVER['REQUEST_URI'];
    $extension substr(strrchr($path'.'), 1);
    $extension "."."$extension";
    $file basename($path$extension);
        if(
    $file == "index"){
            echo(
    'hello, and welcome to my site');
        }
        elseif(
    $file == "random"){
            echo(
    'welcome to a random page!');
        }
        else{
            die(
    "unknown page");
        }
    ?>
    you can also change:
    PHP Code:
    $extension substr(strrchr($path'.'), 1);
    $extension "."."$extension"
    to this:
    PHP Code:
    $extension '.';
    $extension .= substr(strrchr($path'.'), 1); 
    just personal preference.
    Last edited by p4plus2; 03-12-2008 at 09:20 PM.


  •  

    Posting Permissions

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