JBZoo\Utils\FS::clean PHP Method

clean() public static method

Function to strip additional / or \ in a path name.
public static clean ( string $path, string $dirSep = DIRECTORY_SEPARATOR ) : string
$path string The path to clean.
$dirSep string Directory separator (optional).
return string
    public static function clean($path, $dirSep = DIRECTORY_SEPARATOR)
    {
        if (!is_string($path) || empty($path)) {
            return '';
        }
        $path = trim((string) $path);
        if (empty($path)) {
            $path = Vars::get($_SERVER['DOCUMENT_ROOT'], '');
        } elseif ($dirSep == '\\' && $path[0] == '\\' && $path[1] == '\\') {
            $path = "\\" . preg_replace('#[/\\\\]+#', $dirSep, $path);
        } else {
            $path = preg_replace('#[/\\\\]+#', $dirSep, $path);
        }
        return $path;
    }

Usage Example

コード例 #1
0
ファイル: performanceTest.php プロジェクト: JBZoo/Path
 public function setUp()
 {
     $root = FS::clean(__DIR__ . '/test', '/');
     FS::rmdir($root);
     mkdir($root, 0777, true);
     $this->_root = $root;
 }
All Usage Examples Of JBZoo\Utils\FS::clean