Uri\WhatWg\Url::withQuery
PHP function
Edit on GitHub ✎
(PHP 8 >= 8.5.0)
Modify the query component
Description
Uri\WhatWg\Url::withQuery(string|null $query): static
Creates a new URL and modifies its query component.
Parameters
queryNew query component.
Return Values
The modified Uri\WhatWg\Url instance.
Errors/Exceptions InvalidUrlException
Examples
Uri\WhatWg\Url::withQuery basic example
php
<?php
$url = new \Uri\WhatWg\Url("https://example.com?foo=bar");
$url = $url->withQuery("foo=baz");
echo $url->getQuery();
?>The above example will output:
output
foo=bazSee Also
Uri\WhatWg\Url::getQueryUri\Rfc3986\Uri::withQuery