How can you extract the URL path in PHP?

To extract the URL path in PHP, you can use the $_SERVER['REQUEST_URI'] superglobal variable. This variable contains the path and query string of the current URL. You can then manipulate this string to extract just the path portion by using functions like parse_url() or explode().

$url = $_SERVER['REQUEST_URI'];
$path = parse_url($url, PHP_URL_PATH);
echo $path;