3v4l.org

run code in 300+ PHP versions simultaneously
<?php $url = 'https://example.com/folder1/folder2/style.css'; $paths = [ 'img/example1.png', '/img/example2.png', '../img/example3.png', '../../img/example4.png', 'https://example.com/folder1/folder2/example5.png' ]; $folders = explode('/', trim(parse_url($url, PHP_URL_PATH), '/')); array_pop($folders); $prefix = explode('/' . $folders[0] . '/', $url)[0]; // need to be improved using parse_url to re-build // properly the url with the correct syntax for each scheme. function getURLFromPath($path, $prefix, $folders) { if ( parse_url($path, PHP_URL_SCHEME) ) return $path; foreach (explode('/', ltrim($path, '/')) as $item) { if ( $item === '..' ) { array_pop($folders); } elseif ( $item === '.' ) { } else { $folders[] = $item; } } return $prefix . '/' . implode('/', $folders); } foreach ($paths as $path) { echo getURLFromPath($path, $prefix, $folders), PHP_EOL; }
Output for git.master, git.master_jit, rfc.property-hooks
https://example.com/folder1/folder2/img/example1.png https://example.com/folder1/folder2/img/example2.png https://example.com/folder1/img/example3.png https://example.com/img/example4.png https://example.com/folder1/folder2/example5.png

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
108.58 ms | 406 KiB | 5 Q