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" Link to comment https://forums.phpfreaks.com/topic/129435-_sever-help/ Share on other sites More sharing options...
Orio Posted October 21, 2008 Share Posted October 21, 2008 Use basename(). Orio. Link to comment https://forums.phpfreaks.com/topic/129435-_sever-help/#findComment-671070 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 Link to comment https://forums.phpfreaks.com/topic/129435-_sever-help/#findComment-671072 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"; ?> Link to comment https://forums.phpfreaks.com/topic/129435-_sever-help/#findComment-671084 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 Link to comment https://forums.phpfreaks.com/topic/129435-_sever-help/#findComment-671232 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"; ?> Link to comment https://forums.phpfreaks.com/topic/129435-_sever-help/#findComment-671237 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. Link to comment https://forums.phpfreaks.com/topic/129435-_sever-help/#findComment-671242 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. Link to comment https://forums.phpfreaks.com/topic/129435-_sever-help/#findComment-671770 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.