* We'll consider it so always, as we don't want \s in our Unix paths either.
*
* @param string $path
+ * @param string $suffix to remove if present
* @return string
*/
-function wfBaseName( $path ) {
+function wfBaseName( $path, $suffix='' ) {
+ $encSuffix = ($suffix == '')
+ ? ''
+ : ( '(?:' . preg_quote( $suffix, '#' ) . ')?' );
$matches = array();
- if( preg_match( '#([^/\\\\]*)[/\\\\]*$#', $path, $matches ) ) {
+ if( preg_match( "#([^/\\\\]*?){$encSuffix}[/\\\\]*$#", $path, $matches ) ) {
return $matches[1];
} else {
return '';