url_set_query_string
urlSets or updates a query parameter in a URL
Syntax
url_set_query_string(url, key, value) Parameters
url (string) The URL string to modify
key (string) The query parameter key to set
value (string) The value for the query parameter
Returns
string The URL with the query parameter added or updated
Examples
Input:
url_set_query_string("https://example.com", "api_key", "123") Output:
"https://example.com?api_key=123" Input:
url_set_query_string("https://example.com?existing=value", "version", "2") Output:
"https://example.com?existing=value&version=2" The url_set_query_string() function adds or updates a query parameter in a URL. If the URL already has query parameters, the new parameter is appended. If the parameter key already exists, its value is updated.
Usage
Use url_set_query_string() when you need to add tracking parameters, API keys, or other query parameters to URLs in bulk, such as adding UTM parameters to marketing links or versioning to API calls.