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. 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. 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:) 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
Archived
This topic is now archived and is closed to further replies.