MaggsWeb:7

www.maggsweb.com

Where am I…

September 26, 2008 | Comments | PHP

string basename ( string $path [, string $suffix ] )

  1. PATH :: A path. On Windows, both slash (/) and backslash (\) are used as directory separator character. In other environments, it is the forward slash (/).
    suffix.
  2. SUFFIX :: If the filename ends in suffix this will also be cut off.

I use this a lot to distinguish which page I am on. Generally, I would match this to a db record to get page-specific info and settings from the database.

<?php
$path = $_SERVER['PHP_SELF'];
$file = basename($path); // $file is set to "index.php"
$file = basename($path, ".php"); // $file is set to "index"
?>

Write a Comment

Let me know what you think?