Not signed in (Sign In)

Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.


    • CommentAuthorviane
    • CommentTimeNov 28th 2006
     
    I need to get the filename of the page that is loaded.

    I used $PHP_SELF but it returns the folder and file, so, is there a way to either get just the filename, or get rid of everything from the / to the beginning?

    If you can help tonight that would be greatly appreciated!
    • CommentAuthorprogrammer
    • CommentTimeNov 28th 2006
     
    A Regular Expression to get the filename using preg_replace and the "magic" __FILE__ constant could look like this.


    <?php 
    $filename  =  preg_replace('#.*[\\\/]([^\\\/]+)$#',  '$1',  __FILE__);
    ?>

    First argument, the pattern -- #.*[\\\/]([^\\\/]+)$#
    The # on either end is the pattern delimiter.
    Now, from left to right.

    . -- matches anything
    * -- zero or more times
    [\\\/] -- match a back or forward slash
    ( -- start of sub-match
    [^\\\/] -- match anything other than a back or forward slash
    + -- one or more times
    ) -- end of sub-match

    Second argument, the replacement -- '$1'
    $1 -- refers to what was matched in the patterns sub-match.
    • CommentAuthorviane
    • CommentTimeNov 28th 2006
     
    works really well, except that it gives the filename of the include file, not the file calling it.

    folder/index.php is the page, I want $filename to be index.php but it is actually called in head.php which is included in the index.php file.