3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // request to php with type $requestedUri = $_SERVER['REQUEST_URI'] = 'http://www.testing.com/'; $requestedUriWithQuery = $requestedUri . '?name=adam'; // parse request $parsed = parse_url($requestedUriWithQuery); $parsedQuery = []; parse_str($parsed['query'], $parsedQuery); // check request print_r([ $parsed, $parsedQuery ]); // controllers $controllers = [ '/login' => (new class { public function action($request) { return "LOGIN " . implode(", ", $request); } }), '/' => ( new class { public function action($request) { return "Witaj " . $request["name"]; } }), ]; // check controllers if(array_key_exists($parsed["path"], $controllers )){ echo $controllers [ $parsed['path'] ]->action($parsedQuery); }