Browse Source

Added StringHelper::dirname()

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
e9a5b92dd9
  1. 22
      framework/yii/helpers/StringHelperBase.php

22
framework/yii/helpers/StringHelperBase.php

@ -47,8 +47,8 @@ class StringHelperBase
/**
* Returns the trailing name component of a path.
* This method does the same as the php function `basename()` except that it will
* always use \ and / as directory separators, independent of the operating system.
* This method is similar to the php function `basename()` except that it will
* treat both \ and / as directory separators, independent of the operating system.
* This method was mainly created to work on php namespaces. When working with real
* file paths, php's `basename()` should work fine for you.
* Note: this method is not aware of the actual filesystem, or path components such as "..".
@ -70,6 +70,24 @@ class StringHelperBase
}
/**
* Returns parent directory's path.
* This method is similar to `dirname()` except that it will treat
* both \ and / as directory separators, independent of the operating system.
* @param string $path A path string.
* @return string the parent directory's path.
* @see http://www.php.net/manual/en/function.basename.php
*/
public static function dirname($path)
{
$pos = mb_strrpos(str_replace('\\', '/', $path), '/');
if ($pos !== false) {
return mb_substr($path, 0, $pos);
} else {
return $path;
}
}
/**
* Compares two strings or string arrays, and return their differences.
* This is a wrapper of the [phpspec/php-diff](https://packagist.org/packages/phpspec/php-diff) package.
* @param string|array $lines1 the first string or string array to be compared. If it is a string,

Loading…
Cancel
Save