mcmuney Posted March 7, 2009 Share Posted March 7, 2009 I'd like to display the filename extracted from the URL, how can I do that? For example, let's say I'm on my site abc.com/game.php, so what I'd like to show is "game" (taken from game.php). Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/148400-solved-extract-filename-from-url/ Share on other sites More sharing options...
Rodis Posted March 8, 2009 Share Posted March 8, 2009 In your example this would work. $a = $_SERVER['PHP_SELF']; $b = str_replace(".php","","$a"); echo $b; The downside is when the url changes from abc.com/game.php to abc.com/directory/game.php You would have to substract the directory bit to if that isn't the case this would do. $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar. Quote Link to comment https://forums.phpfreaks.com/topic/148400-solved-extract-filename-from-url/#findComment-779266 Share on other sites More sharing options...
opalelement Posted March 8, 2009 Share Posted March 8, 2009 http://us2.php.net/manual/en/function.basename.php Take a look at the example:) Quote Link to comment https://forums.phpfreaks.com/topic/148400-solved-extract-filename-from-url/#findComment-779280 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.