use Symfony\Component\HttpFoundation\Request; $request = Request::createFromGlobals(); $path = $request->getPath(); echo $path; // output: '/example/path'
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; $request = Request::createFromGlobals(); $path = $request->getPath(); if ($path === '/example/path') { echo 'This is the example path'; } else { $response = new Response('Not found', 404); $response->send(); }In this example, we are checking if the path component of the current URL is equal to '/example/path'. If it is, we are displaying a message 'This is the example path'. If not, we are sending a 404 response. The `Request` class and `getPath` method are part of the Symfony HttpFoundation component library.