$currentUrl = "http://example.com/my-page.php?param1=value1"; $path = parse_url($currentUrl, PHP_URL_PATH); echo $path; // outputs "/my-page.php"
$givenUrl = "https://google.com/search?q=php+url+functions"; $path = parse_url($givenUrl, PHP_URL_PATH); echo $path; // outputs "/search"In this example, we define a different URL and retrieve its path using the same `parse_url()` function. This function is a built-in function of PHP, and no external package or library is required to use it.