3raser Posted June 5, 2012 Share Posted June 5, 2012 One of my features on my website relies on the following function that I wrote up real quick: function getPage() { $page = preg_replace('#\/(.+)\/#', '', $_SERVER['PHP_SELF']); $page = str_replace('/', null, $page); return $page; } It gets the page name you're currently on. Such as: http://www.test.com/test.php - It'll return test.php Is there a built in PHP method to do this? Quote Link to comment Share on other sites More sharing options...
abdfahim Posted June 5, 2012 Share Posted June 5, 2012 not sure about built in function, but another method should be $pagename=explode("/",$_SERVER['PHP_SELF']); echo $pagename[count($pagename)-1]; Quote Link to comment Share on other sites More sharing options...
ignace Posted June 5, 2012 Share Posted June 5, 2012 basename echo basename($_SERVER['PHP_SELF']); Quote Link to comment Share on other sites More sharing options...
tarunpahuja Posted June 5, 2012 Share Posted June 5, 2012 In case you want query string as well with file name,you can use this echo basename($_SERVER['REQUEST_URI']); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.