Mecha CMS

Deep learning on using the API.

Class Path

Author: Taufik Nurrohman · 111 Views

Tweet

File/URL path helpers.

Table of Content

Base 

Convert file path to its base name.

Path::B($path, $step = 1, $s = null);

Example:

$test_1 = Path::B('foo\bar\baz.qux');
$test_2 = Path::B('foo\bar\baz.qux', 2);
$test_3 = Path::B('foo-bar-baz.qux', 1, '-');
$test_4 = Path::B('foo.bar.baz.qux', 1, '.');

Result:

$test_1 = 'baz.qux';
$test_2 = 'bar\baz.qux';
$test_3 = 'baz.qux';
$test_4 = 'qux';

Directory 

Convert file path to its directory path.

Path::D($path, $step = 1, $s = null);

Example:

$test_1 = Path::D('foo\bar\baz.qux');
$test_2 = Path::D('foo\bar\baz.qux', 2);
$test_3 = Path::D('foo-bar-baz.qux', 1, '-');
$test_4 = Path::D('foo.bar.baz.qux', 1, '.');

Result:

$test_1 = 'foo\bar';
$test_2 = 'foo';
$test_3 = 'foo-bar';
$test_4 = 'foo.bar.baz';

Name 

Convert file path to its name.

Path::N($path, $x = false);

Example:

$test_1 = Path::N('foo\bar\baz.qux');
$test_2 = Path::N('foo\bar\baz.qux', true);

Result:

$test_1 = 'baz';
$test_2 = 'baz.qux';

Extension 

Get file extension from a file path.

Path::X($path, $fail = false);

Example:

$test_1 = Path::X('foo\bar\baz.qux');
$test_2 = Path::X('foo\bar\baz', 'txt');
$test_3 = Path::X('foo\bar\baz.QUX');

Result:

$test_1 = 'qux';
$test_2 = 'txt';
$test_3 = 'qux';

File/Folder 

Convert file/folder path to a folder path.

Path::F($path, $root = null, $s = DS);

Example:

$test_1 = Path::D('\a\b\c\foo\bar\baz.qux');
$test_2 = Path::D('\a\b\c\foo\bar\baz');
$test_3 = Path::F('\a\b\c\foo\bar\baz.qux');
$test_4 = Path::F('\a\b\c\foo\bar\baz');
$test_5 = Path::F('\a\b\c\foo\bar\baz.qux', '\a\b\c');
$test_6 = Path::F('\a\b\c\foo\bar\baz.qux', null, '/');

Result:

$test_1 = '\a\b\c\foo\bar';
$test_2 = '\a\b\c\foo\bar';
$test_3 = '\a\b\c\foo\bar\baz';
$test_4 = '\a\b\c\foo\bar\baz';
$test_5 = 'foo\bar\baz';
$test_6 = '/a/b/c/foo/bar/baz';

0 Comments

No comments yet.