Mecha CMS

Deep learning on using the API.

Class Path

Author: Taufik Nurrohman · 87 Views

Tweet

File/URL path helpers.

Table of Content

  1. B 
  2. D 
  3. N 
  4. X 
  5. F 

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

Convert file path to its base name:

$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, '.');

Results:

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

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

Convert file path to its directory path:

$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, '.');

Results:

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

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

Convert file path to its name:

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

Results:

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

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

Get file extension from a file path:

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

Results:

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

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

Convert file/folder path to a folder path:

$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, '/');

Results:

$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.