drupal_basename

7 file.inc drupal_basename($uri, $suffix = NULL)
8 file.inc drupal_basename($uri, $suffix = NULL)

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

http://bugs.php.net/bug.php?id=37738

basename()

Related topics

32 calls to drupal_basename()

File

includes/file.inc, line 2290
API for handling file uploads and server file management.

Code

function drupal_basename($uri, $suffix = NULL) {
  $separators = '/';
  if (DIRECTORY_SEPARATOR != '/') {
    // 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;
}

Comments

Does this code need to

Does this code need to replace something in the file.inc? On my line 2288 I have:

@param $uri
* A URI or pathname.
* @param $mode
* By default the Drupal mode is used.
* @param $recursive
* Default to FALSE.
* @param $context
* Refer to http://php.net/manual/en/ref.stream.php
*
* @return
* Boolean TRUE on success, or FALSE on failure.
*
* @see mkdir()
* @ingroup php_wrappers
*/

Login or register to post comments