Get the file name without the directories

in

Shocking! This tutorial teaches people very inefficient codes!
Mountains of inefficientness running though every line of the tutorial! AHHHHHhhh
I'm not going to criticize not using __FILE__ part, since sometimes, $_SERVER["SCRIPT_NAME"] can be different from __FILE__.
$file = $_SERVER["SCRIPT_NAME"];
but I have to say something about how to get the a file name without the directories.

$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];

Build ups of this kind of small unpolished gears could end up with huge performance hit(even though it's usually not noticeable among the users).
I suggest a MUCH faster method:
$pfile = basename(__FILE__);

Post new comment

The content of this field is kept private and will not be shown publicly.
If you have a Gravatar account, used to display your avatar. If you have a Gravatar account, used to display your avatar.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <span> <fn>
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.

More information about formatting options

What is 3 + 17?
To combat spam, please solve the math question above.
Honey Pot that kill bots