imarockstar Posted October 21, 2008 Share Posted October 21, 2008 this is the little code snippet I have <?php $page = $_SERVER['PHP_SELF']; echo "$page"; ?> its returning ... "/directory/pagename.php" ... my question is .. how do i get rid of the "/directory/" and just show "pagename.php" Quote Link to comment Share on other sites More sharing options...
Orio Posted October 21, 2008 Share Posted October 21, 2008 Use basename(). Orio. Quote Link to comment Share on other sites More sharing options...
php.ajax.coder Posted October 21, 2008 Share Posted October 21, 2008 Try this 'SCRIPT_FILENAME' if not you should be able to find it here -> http://uk3.php.net/manual/en/reserved.variables.server.php Quote Link to comment Share on other sites More sharing options...
johntp Posted October 21, 2008 Share Posted October 21, 2008 Try this. <?php $pages = $_SERVER['PHP_SELF']; $pages2 = explode("/", $pages); $page = $pages2[2]; echo "$page"; ?> Quote Link to comment Share on other sites More sharing options...
imarockstar Posted October 21, 2008 Author Share Posted October 21, 2008 ok awsome .. so if I wanted to take off the ".php" ... how can that be done ? thx b Quote Link to comment Share on other sites More sharing options...
trq Posted October 21, 2008 Share Posted October 21, 2008 <?php $page = str_replace('.php','',basename($_SERVER['PHP_SELF'])); echo "$page"; ?> Quote Link to comment Share on other sites More sharing options...
discomatt Posted October 21, 2008 Share Posted October 21, 2008 substr( $str, 0, -4 ); would probably be a bit faster than str_replace. Quote Link to comment Share on other sites More sharing options...
Orio Posted October 22, 2008 Share Posted October 22, 2008 As I already mentioned: Use basename(). Orio. Example: <?php $filename = "folder/scripts/index.php"; echo basename($filename, ".php"); //Output- "index" ?> See more examples at the link provided... Orio. 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.