php8.5
Home/ Manual/ whatwg / url/ Uri\WhatWg\Url::withQuery

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

query

New 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=baz

See Also

  • Uri\WhatWg\Url::getQuery
  • Uri\Rfc3986\Uri::withQuery

Source: reference/uri/uri/whatwg/url/withquery.xml · from the official PHP manual (php/doc-en)