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? Link to comment https://forums.phpfreaks.com/topic/41293-solved-_server-echo-just-the-filename/ 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']); ?> Link to comment https://forums.phpfreaks.com/topic/41293-solved-_server-echo-just-the-filename/#findComment-200086 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 Link to comment https://forums.phpfreaks.com/topic/41293-solved-_server-echo-just-the-filename/#findComment-200088 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']; Link to comment https://forums.phpfreaks.com/topic/41293-solved-_server-echo-just-the-filename/#findComment-200092 Share on other sites More sharing options...
Jenk Posted March 5, 2007 Share Posted March 5, 2007 <?php echo basename($_SERVER['SCRIPT_NAME']); ?> Link to comment https://forums.phpfreaks.com/topic/41293-solved-_server-echo-just-the-filename/#findComment-200098 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.