php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63279 Mixing the $suffix parameter from basename()
Submitted: 2012-10-14 20:08 UTC Modified: 2020-03-04 23:53 UTC
From: klaussantana at gmail dot com Assigned:
Status: Suspended Package: Filesystem function related
PHP Version: Irrelevant OS: Any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: klaussantana at gmail dot com
New email:
PHP Version: OS:

 

 [2012-10-14 20:08 UTC] klaussantana at gmail dot com
Description:
------------
New functionalities for basename().

Syntax:
basename( mixed $path[, mixed $suffix = null[, bool $case_sensitive = false]] );

Summary:
basename() will return the base name of the last component of the path. If it is 
a file name the function will return the name of the file. If it is a directory 
the function will return the name of the directory.

The $path parameter accepts a string or an array of strings to extract the base 
name of the last component of the path.

The $suffix parameter accepts a string or an array of strings to be compared 
against each $path value.

The $case_sensitive parameter accepts a boolean value (true or false) that 
indicates if the $path and $suffix must be compared using "case sensitive" or 
"case insensitive" comparison method.

Return value:
A single string or an array of strings with the base name of the last component 
of the corresponding string stripping $suffix from it.

NOTE:
By default, the function will use "case insensitive" comparison method.

Test script:
---------------
$Files = array();

$Files[] = 'path/to/images/my-computer.jpg';
$Files[] = 'path/to/images/My-Dog.Jpeg';
$Files[] = 'path/to/images/loading.gif';
$Files[] = 'path/to/images/sketch.bmp';

// Overwriting the array
$Files = basename( $Files, array('.bmp', '.jpg', '.jpeg', '.gif', '.png') );

print_r($Files);

Expected result:
----------------
Array
(
    [0] => my-computer
    [1] => My-Dog
    [2] => loading
    [3] => sketch
)

Actual result:
--------------
null

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-04 23:53 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2020-03-04 23:53 UTC] cmb@php.net
Looks like this could be implemented in userland without too much
trouble, and I cannot immediately see a benefit of having this
functionality in PHP core.  That doesn't mean that this couldn't
be a useful feature, but it appears that it should be discussed,
and this bug tracker is rather unsuitable for such discussions.
So I encourage anybody interested in this to bring it up on the
internals mailing list[1].  For the time being, I'm suspending
this ticket.

[1] <https://www.php.net/mailing-lists.php#internals>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 08:02:42 2024 UTC