-5

How do you get JUST the current files name that is being used? I need the name only (myFile.php NEEDS TO BE myFile)

$_SERVER and __FILE__ constants are NOT the answers I am looking for.

gen_Eric
  • 214,658
  • 40
  • 293
  • 332
MattTanner
  • 246
  • 1
  • 4
  • 12
  • 5
    http://php.net/manual/en/function.pathinfo.php If you cannot find something that exactly matches your requirements - combine functions. There is obviously no function `run_facebook();`. So in your case - use `__FILE__` and mentioned function. – zerkms Jan 27 '14 at 20:59
  • Possible duplicate of 'http://stackoverflow.com/questions/4221333/get-the-current-script-file-name' – dev7 Jan 27 '14 at 21:00

2 Answers2

2
basename(__FILE__, '.php');

See also here: http://php.net/basename, or, if you like

pathinfo(__FILE__, PATHINFO_FILENAME);

This last one works also if the extension is different from .php without the need to specify it, see http://php.net/manual/en/function.pathinfo.php

Matteo Tassinari
  • 17,408
  • 7
  • 58
  • 80
0

Try strstr :

<?php
$file  = 'myFile.php';
$name = strstr($file, '.');
echo $name; // prints .php

$file  = 'myFile.php';
$name = strstr($file, '.' ,true);
echo $name; // prints myFile
?>

You can find more examples on how to use this at http://us1.php.net/manual/en/function.strstr.php

This should work for you.

natmed91
  • 47
  • 2
  • 4