PHP code example of stein197 / path
1. Go to this page and download the library: Download stein197/path library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
stein197 / path example snippets
use Stein197\FileSystem\Path;
$p = Path::new('/var/www/html/project/public');
// Stringable interface implementation
(string) $p; // '/var/www/html/project/public'
// ArrayAccess interface implementation
isset($p[1]); // true, it's 'var' part
$p[-2]; // 'project'
$p[3] = 'html'; // an exception, paths are read-only
unset($p[4]); // an exception, paths are read-only
// Countable interface implementation
sizeof($p); // 5
// Iterator interface implementation
[...$p]; // ['', 'var', 'www', 'html', 'project', 'public']
// Stein197\Equalable interface implementation
$p->equals('\\var///www/html/project/public/'); // true
// Public readonly properties
$p->isDOS; // false
$p->isUnix; // true
$p->isRoot; // false
$p->isAbsolute; // true
$p->isRelative; // false
$p->depth; // 5
$p->drive; // null; Valid only for DOS paths
$p->path; // '/var/www/html/project/public'
// Dynamic methods
$p->getElement(1); // 'var'; The same as $p[1]
$p->getParent(); // Path('/var/www/html/project')
$p->getSubpath(2, -2); // Path('www/html/project')
$p->toAbsolute('/'); // Path('/var/www/html/project/public'); The path itself since it's already absolute
$p->toRelative('/var/www'); // Path('html/project/public')
$p->format([
'separator' => '\\',
'trailingSlash' => true
]); // '\\var\\www\\html\\project\\public\\'
$p->startsWith('/var'); // true
$p->endsWith('public'); // true
$p->isChildOf('/var/www/html/project'); // true
$p->isParentOf('/var/www/html/project/public/index.php'); // true
$p->