Reputation: 10570
I have these urls
something2/something3/fileName.php
something2/something3/fileName.php?para=someting¶m2=something2
I want to get the fileName
without the .php
extension and without the paramets,
note: not all the urls have parameters.
$phpFileName = basename($_SERVER['REQUEST_URI'], ".php");//without .php extension
that works only when there are no parameters in the urls, but when there are parameters in the url, i got like this:
fileName.php?parm=something¶m=something
how can I remove these parameters please and get just the fileName
?
thanks
Upvotes: 1
Views: 2085
Reputation: 78994
Get the path from the URL first with parse_url
:
$phpFileName = basename(parse_url($_SERVER['REQUEST_URI'], PHP_PATH), ".php");
You could also look at pathinfo
.
Upvotes: 2
Reputation: 21531
Well if the code is in the file itself you can use...
$phpFileName = basename(__FILE__, ".php");
The __FILE__
is a magic constant to the current file being executed.
Otherwise just remove the query string using explode
first...
$qs = explode("?", $_SERVER['REQUEST_URI']);
$phpFileName = basename($qs[0], ".php");
Upvotes: 2