3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function test($DIRECTORY_SEPARATOR, $source, $path, $expected) { $folder = str_replace(rtrim($source, $DIRECTORY_SEPARATOR), '', dirname($path)); echo "Expected: $expected\n"; echo "Actual: $folder\n"; echo "--------------\n"; } test('/', '/site/path', '/site/path/backed/up/item.txt', '/backed/up'); test('/', '/site/path/', '/site/path/backed/up/item.txt', '/backed/up'); test('\\', 'C:\\site\\path', 'C:/site/path/backed/up/item.txt', '/backed/up'); test('\\', 'C:\\site\\path\\', 'C:/site/path/backed/up/item.txt', '/backed/up'); test('\\', 'C:/site/path', 'C:/site/path/backed/up/item.txt', '/backed/up'); test('\\', 'C:/site/path/', 'C:/site/path/backed/up/item.txt', '/backed/up');
Output for 5.6.0 - 7.3.1
Expected: /backed/up Actual: /backed/up -------------- Expected: /backed/up Actual: /backed/up -------------- Expected: /backed/up Actual: C:/site/path/backed/up -------------- Expected: /backed/up Actual: C:/site/path/backed/up -------------- Expected: /backed/up Actual: /backed/up -------------- Expected: /backed/up Actual: backed/up --------------