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: -
From: klaussantana at gmail dot com Assigned:
Status: Open Package: Filesystem function related
PHP Version: Irrelevant OS: Any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Oct 22 03:01:25 2018 UTC