function drupal_basename

Gets the filename from a given path.

PHP's basename() does not properly support streams or filenames beginning with a non-US-ASCII character.

See also


Related topics

32 calls to drupal_basename()
color_scheme_form_submit in drupal/modules/color/color.module
Form submission handler for color_scheme_form().
DrupalErrorCollectionUnitTest::assertError in drupal/modules/simpletest/tests/common.test
Assert that a collected error matches what we are expecting.
DrupalLocalStreamWrapper::getLocalPath in drupal/includes/
Returns the canonical absolute path of the URI, if possible.
DrupalLocalStreamWrapper::getMimeType in drupal/includes/
Base implementation of getMimeType().
drupal_get_css in drupal/includes/
Returns a themed representation of all stylesheets to attach to the page.

... See full list


drupal/includes/, line 2391
API for handling file uploads and server file management.


function drupal_basename($uri, $suffix = NULL) {
  $separators = '/';

    // For Windows OS add special separator.
    $separators .= DIRECTORY_SEPARATOR;

  // Remove right-most slashes when $uri points to directory.
  $uri = rtrim($uri, $separators);

  // Returns the trailing part of the $uri starting after one of the directory
  // separators.
  $filename = preg_match('@[^' . preg_quote($separators, '@') . ']+$@', $uri, $matches) ? $matches[0] : '';

  // Cuts off a suffix from the filename.
  if ($suffix) {
    $filename = preg_replace('@' . preg_quote($suffix, '@') . '$@', '', $filename);
  return $filename;