$router = new \Bramus\Router\Router(); $router->get('/hello/(\w+)', function($name) { echo 'Hello ' . $name; }); $router->run(); $path = $router->getCurrentRoute()->getPath(); echo $path; // Output: /hello/(\w+)
use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; $collection = new RouteCollection(); $collection->add('hello', new Route('/hello/{name}', ['name' => 'World'])); $path = $collection->get('hello')->getPath(); echo $path; // Output: /hello/{name}In this example, we create a new Symfony RouteCollection and add a route to it. We then use the getPath function to retrieve the path of the added route. Package Library: Symfony Routing Component