3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_converted_url($full_url) { $urls_to_convert = ['/some/url/', '/other/url']; $parsed_url = parse_url($full_url); $path = $parsed_url['path']; foreach ($urls_to_convert as $url_to_convert) { if (strpos($path, $url_to_convert, 0) !== false) { return $url_to_convert; } } return $path; } echo get_converted_url('/test/some/url/') . "\n"; echo get_converted_url('/some/url/a/b/') . "\n"; echo get_converted_url('/other/url/a/b/') . "\n"; echo get_converted_url('/strange/url/a/b/') . "\n";
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.14
/some/url/ /some/url/ /other/url /strange/url/a/b/

preferences:
104.93 ms | 406 KiB | 5 Q