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
pathNew 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
/bazSee Also
Uri\WhatWg\Url::getPathUri\Rfc3986\Uri::withPath