3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!function_exists("str_ends_with")) { function str_ends_with($haystack, $needle) { return strrpos($haystack, $needle) === strlen($haystack) - strlen($needle); } } $urls = [ "https://www.example.gov.us/directory_1/directory_2/directory_3/index.php", "https://www.example.gov.us/directory_1/directory_2/directory_3/index", "https://www.example.gov.us/directory_1/directory_2/directory_3/" ]; foreach ($urls as $url) { printf( "From %s, got '%s'%s", $url, str_ends_with($url, "/") ? "" : basename($url), PHP_EOL ); }

preferences:
102.05 ms | 408 KiB | 5 Q