PHP code example of loilo / node-path

1. Go to this page and download the library: Download loilo/node-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/ */

    

loilo / node-path example snippets


use Loilo\NodePath\Path;

Path::basename('/foo/bar/baz/asdf/quux.html') === 'quux.html';
Path::basename('/foo/bar/baz/asdf/quux.html', '.html') === 'quux';

Path::dirname('/foo/bar/baz/asdf/quux') === '/foo/bar/baz/asdf';

Path::extname('index.html') === '.html';
Path::extname('index.coffee.md') === '.md';
Path::extname('index.') === '.';
Path::extname('index') === '';
Path::extname('.index') === '';
Path::extname('.index.md') === '.md';

// If $dir, $root and $base are provided,
// $dir . Path::getSeparator() . $base
// will be returned. $root is ignored.
Path::format([
  'root' => '/ignored',
  'dir' => '/home/user/dir',
  'base' => 'file.txt'
]) === '/home/user/dir/file.txt';

// $root will be used if $dir is not specified.
// If only $root is provided or $dir is equal to $root then the
// platform separator will not be  '/data/orandea/impl/bbb') === '../../impl/bbb';

Path::resolve('/foo/bar', './baz') === '/foo/bar/baz';
Path::resolve('/foo/bar', '/tmp/file/') === '/tmp/file';
Path::resolve('wwwroot', 'static_files/png/', '../gif/image.gif');
// If the current working directory is /home/myself/node,
// this returns '/home/myself/node/wwwroot/static_files/gif/image.gif'

Path::basename('C:\\temp\\myfile.html') === 'C:\\temp\\myfile.html';

Path::basename('C:\\temp\\myfile.html') === 'myfile.html';

use Loilo\NodePath\WindowsPath;

WindowsPath::basename('C:\\temp\\myfile.html') === 'myfile.html';

use Loilo\NodePath\PosixPath;

PosixPath::basename('/tmp/myfile.html') === 'myfile.html';