note 85597 modified in function.basename by felipe
| From: | felipe@php.net | Date: | Wed, 10 Sep 2008 22:27:20 +0000 |
| Subject: | note 85597 modified in function.basename by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-144324@lists.php.net to get a copy of this message | ||
It might be useful to have a version of the function basename working with arrays too.
<?php
function a_basename( $file, $exts )
{
$onlyfilename = end( explode( "/", $file ) );
if( is_string( $exts ) )
{
if ( strpos( $onlyfilename, $exts, 0 ) !== false )
$onlyfilename = str_replace( $exts, "", $onlyfilename );
}
else if ( is_array( $exts ) )
{
// works with PHP version <= 5.x.x
foreach( $exts as $KEY => $ext )
{
$onlyfilename = str_replace( $ext, "", $onlyfilename );
}
}
return $onlyfilename ;
}
?>
--was--
It might be useful to have a version of the function basename working with arrays too.
function a_basename( $file, $exts )
{
$onlyfilename = end( explode( "/", $file ) );
if( is_string( $exts ) )
{
if ( strpos( $onlyfilename, $exts, 0 ) !== false )
$onlyfilename = str_replace( $exts, "", $onlyfilename );
}
else if ( is_array( $exts ) )
{
// works with PHP version <= 5.x.x
foreach( $exts as $KEY => $ext )
{
$onlyfilename = str_replace( $ext, "", $onlyfilename );
}
}
return $onlyfilename ;
}
http://php.net/manual/en/function.basename.php