Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Path.php

function Path::getFilenameWithoutExtension

Returns the file name without the extension from a file path.

Parameters

string|null $extension if specified, only that extension is cut: off (may contain leading dot)

File

vendor/symfony/filesystem/Path.php, line 257

Class

Path
Contains utility methods for handling path strings.

Namespace

Symfony\Component\Filesystem

Code

public static function getFilenameWithoutExtension(string $path, ?string $extension = null) : string {
    if ('' === $path) {
        return '';
    }
    if (null !== $extension) {
        // remove extension and trailing dot
        return rtrim(basename($path, $extension), '.');
    }
    return pathinfo($path, \PATHINFO_FILENAME);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal