3v4l.org

run code in 500+ PHP versions simultaneously
<?php // Sample URLs. In practice there'd just be one which comes from $_SERVER['REQUEST_URI'] $urls = [ 'https://example.com', 'https://example.com/', 'https://example.com/en', 'https://example.com/en/', 'https://example.com/en/something', 'https://example.com/en/something/cheese', 'https://example.com/en/something/cheese/stuff', ]; foreach($urls as $url){ $urlParts = parse_url($url); $path = $urlParts['path'] ?? '/'; $pathParts = array_values(array_filter(explode('/', $path))); $lang = $menu = $page = $key = null; echo 'Url tested: ' . $url; echo PHP_EOL; if(!$pathParts){ echo 'Home'; }else{ // I would probably write this with a switch on the count(pathParts), or do some better // parsing here maybe, but this just shows what could happen @[0 => $lang, 1 => $menu, 2 => $page, 3 => $key] = $pathParts; echo sprintf('Lang=%1$s, Menu=%2$s, Page=%3$s, Key=%4$s', $lang, $menu, $page, $key); } echo PHP_EOL, PHP_EOL; }

preferences:
41.77 ms | 1050 KiB | 5 Q