PHP code example of bhittani / path

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

    

bhittani / path example snippets




 = new \Bhittani\Path\Path();

// Use the API calls as demonstrated below.

echo $path->sanitize('\foo/bar\baz'); // '/foo/bar/baz'

echo $path->join('foo', './bar', '../baz/..'); // 'foo'

echo $path->absolute('/foo'); // '/foo'
echo $path->absolute('foo'); // getcwd().'/foo'
echo $path->absolute('/foo', true); // getcwd().'/foo'

echo $path->normalize('/foo', 'bar/', '../baz/'); // '/foo/baz'
echo $path->normalize('foo', './bar', '/../baz'); // getcwd().'/foo/baz'

echo $path->isAbsolute('/foo/bar'); // true
echo $path->isAbsolute('foo/bar'); // false

echo $path->isRoot('/'); // true
echo $path->isRoot('c:/'); // true
echo $path->isRoot('http://'); // true
echo $path->isRoot('http://example.com'); // true
echo $path->isRoot('/foo'); // false



hittani\Path\StaticPath;

echo StaticPath::normalize('/foo/', '/bar/'); // '/foo/bar'