All4172 Posted March 5, 2007 Share Posted March 5, 2007 I want to echo just the filename of a current page. When I use something like $_SERVER['PHP_SELF'] it gives the directory and the filename. Any ideas on how to show JUST the filename? Quote Link to comment Share on other sites More sharing options...
camdagr81 Posted March 5, 2007 Share Posted March 5, 2007 <?php // get_file_name() Function function get_file_name($string) { $str_array = explode("/", $string); $token = count($str_array) - 1; $file = explode("?", $str_array[$token]); return $file[0]; } // Usage: echo get_file_name($_SERVER['PHP_SELF']); ?> Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted March 5, 2007 Share Posted March 5, 2007 try: print_r pathinfo($_SERVER['PHP_SELF']); monk.e.boy Quote Link to comment Share on other sites More sharing options...
camdagr81 Posted March 5, 2007 Share Posted March 5, 2007 try: print_r pathinfo($_SERVER['PHP_SELF']); monk.e.boy $path = pathinfo($_SERVER['PHP_SELF']); echo $path['basename']; Quote Link to comment Share on other sites More sharing options...
Jenk Posted March 5, 2007 Share Posted March 5, 2007 <?php echo basename($_SERVER['SCRIPT_NAME']); ?> 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.