url_set_path
urlChanges the path of a URL
Syntax
url_set_path(url, path) Parameters
url (string) The URL string to modify
path (string) The new path to set
Returns
string The URL with the updated path
Examples
Input:
url_set_path("https://example.com/old", "/new") Output:
"https://example.com/new" Input:
url_set_path("https://example.com/old?query=value", "/api/v2") Output:
"https://example.com/api/v2?query=value" The url_set_path() function replaces the path component of a URL with a new path, preserving the protocol, domain, port, and query parameters.
Usage
Use url_set_path() when you need to change URL paths, such as updating API versions, redirecting to different endpoints, or transforming URL structures in bulk.