What are the key components involved in URL routing in PHP, specifically when using MVC?

URL routing in PHP involves mapping incoming URLs to specific controllers and actions in an MVC framework. Key components include defining routes, parsing incoming URLs, and executing the corresponding controller method based on the route. This allows for clean and organized handling of different requests in a PHP application.

// Define routes
$routes = [
    '/' => 'HomeController@index',
    '/about' => 'AboutController@index',
    '/contact' => 'ContactController@index'
];

// Parse incoming URL
$request_uri = $_SERVER['REQUEST_URI'];
$route = rtrim($request_uri, '/');
if(array_key_exists($route, $routes)) {
    list($controller, $method) = explode('@', $routes[$route]);
    $controller = new $controller();
    $controller->$method();
} else {
    echo "404 Not Found";
}