function FileSystem::basename
Same name in other branches
- 9 core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::basename()
- 8.9.x core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::basename()
- 10 core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::basename()
Overrides FileSystemInterface::basename
3 calls to FileSystem::basename()
- FileSystem::getDestinationFilename in core/
lib/ Drupal/ Core/ File/ FileSystem.php - Determines the destination path for a file.
- FileSystem::prepareDestination in core/
lib/ Drupal/ Core/ File/ FileSystem.php - Prepares the destination for a file copy or move operation.
- FileSystem::tempnam in core/
lib/ Drupal/ Core/ File/ FileSystem.php - Creates a file with a unique filename in the specified directory.
File
-
core/
lib/ Drupal/ Core/ File/ FileSystem.php, line 153
Class
- FileSystem
- Provides helpers to operate on files and stream wrappers.
Namespace
Drupal\Core\FileCode
public function 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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.