PHP code example of tomaskraus / path-utils

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

    

tomaskraus / path-utils example snippets


Path::join("myapp/", "/dist/app.zip") );
// => "myapp/dist/app.zip"

$pth = new Path("/var/www/myApp/");
$pth->root(); // => "/var/www/myApp"

$pth->root("conf/local.php");
// => "/var/www/myapp/conf/local.php"


Tomaskraus\PathUtils\Path;

/* remember our web application root */
$pth = new Path("/var/www/myApp/");

/* one can use even a non-existent root path */
/* just acts as a prefix path */
$pth2 = new Path("foo");

var_dump( $pth->root() );
// => "/var/www/myApp"
//everything is returned without the trailing path separator

var_dump( $pth2->root() );
// => "foo"

/* we can create new, non-existing path strings, based on our web application root */
var_dump( $pth->root("conf/file-to-be-created.php") );
// => "/var/www/myapp/conf/file-to-be-created.php"

var_dump( $pth->root("/conf/file-to-be-created.php") );
// => "/var/www/myapp/conf/file-to-be-created.php"
// returns the same... smart path separator handling

/* another instance with the different root */
var_dump( $pth2->root("/conf/file-to-be-created.php") );
// => "foo/conf/file-to-be-created.php"


/* root() does not normalize paths */
var_dump( $pth->root("/../conf/file-to-be-created.php") );
// => "/var/www/myApp/../conf/file-to-be-created.php"

/* path-safe