How can $_SERVER['REQUEST_URI'] be utilized in PHP to extract values from URLs?

$_SERVER['REQUEST_URI'] can be utilized in PHP to extract values from URLs by parsing the URL and extracting the desired values using string manipulation or regular expressions. This can be useful when working with dynamic URLs or routing in web applications.

$url = $_SERVER['REQUEST_URI'];

// Extracting values from URL using string manipulation
$parts = explode('/', $url);
$value = $parts[2]; // Assuming the value is at a specific position in the URL

// Extracting values from URL using regular expressions
preg_match('/\/(\d+)/', $url, $matches);
$value = $matches[1]; // Assuming the value is a number in the URL