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

Uri\WhatWg\Url::withPath

PHP function Edit on GitHub ✎

(PHP 8 >= 8.5.0)

Modify the path component

Description

Uri\WhatWg\Url::withPath(string $path): static

Creates a new URL and modifies its path component.

Parameters

path

New path component.

Return Values

The modified Uri\WhatWg\Url instance.

Errors/Exceptions InvalidUrlException

Examples

Uri\WhatWg\Url::withPath basic example

php
<?php
$url = new \Uri\WhatWg\Url("https://example.com/foo/bar");
$url = $url->withPath("/baz");

echo $url->getPath();
?>

The above example will output:

output
/baz

See Also

  • Uri\WhatWg\Url::getPath
  • Uri\Rfc3986\Uri::withPath

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