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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    161
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Variable for Pagename

    How do you make a PHP variable that is equal to the page name (e.g. index.php) also is it possible to make one that is just equal to the file name without the extension (e.g. index)

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    <?php

    echo $_SERVER["PHP_SELF"];

    ?>
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Posts
    161
    Thanks
    2
    Thanked 0 Times in 0 Posts
    does that get name only or name and extension?

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    That will give you file name and extension.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    Regular Coder
    Join Date
    Feb 2003
    Location
    East Side/West Side
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Or you could just echo $PHP_SELF, am I right? :-)

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Actually now that I read more carefully, PHP_SELF will also output the path. Here is a functoin posted at php.net that removes the path and file extension:

    PHP Code:
    function filename() {
    $host $_SERVER['PHP_SELF'];
    $i strlen ($host);
    while ((
    $stop!=1) and ($i>=0)) {
    if (
    $host[$i] != "/") {
    $new $host[$i] . $new;
    $i--;
    } else 
    $stop=1;

    $new explode ('.'$new);
    return 
    $new[0];

    Just call the function whenever you want the filename without extension.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Posting Permissions

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