require_once 'vendor/autoload.php'; use \Route\Run; $run = new Run(); $run->add('/', function() { echo 'Home Page'; }); $run->add('/about', function() { echo 'About Page'; }); $run->add('/contact', function() { echo 'Contact Page'; }); $run->add('/blog/(\d+)', function($id) { echo 'Blog Post ' . $id; }); $run->run();
require_once 'vendor/autoload.php'; use \Route\Run; use \Route\RouteException; $run = new Run(); $run->add('/hello/(\w+)', function($name) { echo 'Hello, ' . $name . '!'; }); try { $run->run(); } catch (RouteException $e) { echo 'Route not found.'; }In this example, we've added a route that accepts a parameter for the name, and will display a personalized greeting. We've also added a try-catch block to handle any RouteException that may be thrown if the requested route is not found. Based on these examples, it's likely that PHP Route Run is the package library being used.