php Конкатенация путей к файлу/папке

Установив пакет, используйте Path::concat() выполнит конкатенацию, добавив/убрав если нужно слеши:

use ItForFree\rusphp\File\Path;

$fullPath = Path::concat(
      ['file/my/', '/folder/to/folder', 'path/to/my.png'],
        '/'
);

Цитата из теста:



$tester = $this->tester;

$testValues = [
	[
		['file/my', 'path/to'],
		'file/my/path/to'
	],
	[
		['file/my/', '/path/to'],
		'file/my/path/to'
	],
	[
		['file/my/', 'path/to'],
		'file/my/path/to'
	],
	[
		['file/my/', 'path/to/my.png'],
		'file/my/path/to/my.png'
	],
	[
		['file/my/', 'folder/to/folder', 'path/to/my.png'],
		'file/my/folder/to/folder/path/to/my.png'
	],
	[
		['file/my/', '/folder/to/folder', 'path/to/my.png'],
		'file/my/folder/to/folder/path/to/my.png'
	]
];

foreach ($testValues as $test) {
	$tester->assertSame(Path::concat($test[0], '/'), $test[1]);
}

Key Words for FKN + antitotal forum (CS VSU):