0

I have these types of urls

something1/anotherThing1/View/fileName.php

something2/anotherThing2/View/fileName2.php?variable1=value1&variable2=value2

...

I want to get the fileName without the .php

I tried this

$_SERVER['REQUEST_URI']

but it seems it gives me the whole url.

Maybe I need a regualr expression.

Could you help me please. i am not good in PHP and i just need this small issue.

appreciate it

Marco Dinatsoli
  • 10,322
  • 37
  • 139
  • 253
  • Do you want to be able to run the file without the extension or do you want to get the name of the file inside the script, getting rid of the extension? clear that out –  Dec 27 '14 at 13:26
  • Maybe `__FILE__`? If you're inside the actual file and not in an included one – casraf Dec 27 '14 at 13:28
  • @JuanRocamonde i need the name of the file inside a script, that file name is in the url and i want to get it inside a script. is that clear please? – Marco Dinatsoli Dec 27 '14 at 13:29
  • you can get rid of the .php extension by using `trim($var, ".php")` –  Dec 27 '14 at 13:30

1 Answers1

3
 echo basename($_SERVER["SCRIPT_FILENAME"]); //with php
    echo '<br>';
    echo basename($_SERVER['REQUEST_URI'], ".php");//without php

check this answer

Get the current script file name

Community
  • 1
  • 1
Ranjeet Singh
  • 924
  • 5
  • 11